@@ -1011,7 +1011,8 @@ func (l *loggingT) exit(err error) {
10111011logExitFunc (err )
10121012return
10131013}
1014- l .flushAll ()
1014+ files := l .flushAll ()
1015+ l .syncAll (files )
10151016OsExit (2 )
10161017}
10171018
@@ -1223,24 +1224,38 @@ func StartFlushDaemon(interval time.Duration) {
12231224// lockAndFlushAll is like flushAll but locks l.mu first.
12241225func (l * loggingT ) lockAndFlushAll () {
12251226l .mu .Lock ()
1226- l .flushAll ()
1227+ files := l .flushAll ()
12271228l .mu .Unlock ()
1229+ // Some environments are slow when syncing and holding the lock might cause contention.
1230+ l .syncAll (files )
12281231}
12291232
1230- // flushAll flushes all the logs and attempts to "sync" their data to disk.
1233+ // flushAll flushes all the logs
12311234// l.mu is held.
1232- func (l * loggingT ) flushAll () {
1235+ func (l * loggingT ) flushAll () []flushSyncWriter {
1236+ files := make ([]flushSyncWriter , 0 , severity .NumSeverity )
12331237// Flush from fatal down, in case there's trouble flushing.
12341238for s := severity .FatalLog ; s >= severity .InfoLog ; s -- {
12351239file := l .file [s ]
12361240if file != nil {
12371241_ = file .Flush () // ignore error
1238- _ = file .Sync () // ignore error
12391242}
1243+ files = append (files , file )
12401244}
12411245if logging .loggerOptions .flush != nil {
12421246logging .loggerOptions .flush ()
12431247}
1248+ return files
1249+ }
1250+
1251+ // syncAll attempts to "sync" their data to disk.
1252+ func (l * loggingT ) syncAll (files []flushSyncWriter ) {
1253+ // Flush from fatal down, in case there's trouble flushing.
1254+ for _ , file := range files {
1255+ if file != nil {
1256+ _ = file .Sync () // ignore error
1257+ }
1258+ }
12441259}
12451260
12461261// CopyStandardLogTo arranges for messages written to the Go "log" package's
0 commit comments