@@ -1011,7 +1011,8 @@ func (l *loggingT) exit(err error) {
1011
1011
logExitFunc (err )
1012
1012
return
1013
1013
}
1014
- l .flushAll ()
1014
+ files := l .flushAll ()
1015
+ l .syncAll (files )
1015
1016
OsExit (2 )
1016
1017
}
1017
1018
@@ -1223,24 +1224,38 @@ func StartFlushDaemon(interval time.Duration) {
1223
1224
// lockAndFlushAll is like flushAll but locks l.mu first.
1224
1225
func (l * loggingT ) lockAndFlushAll () {
1225
1226
l .mu .Lock ()
1226
- l .flushAll ()
1227
+ files := l .flushAll ()
1227
1228
l .mu .Unlock ()
1229
+ // Some environments are slow when syncing and holding the lock might cause contention.
1230
+ l .syncAll (files )
1228
1231
}
1229
1232
1230
- // flushAll flushes all the logs and attempts to "sync" their data to disk.
1233
+ // flushAll flushes all the logs
1231
1234
// l.mu is held.
1232
- func (l * loggingT ) flushAll () {
1235
+ func (l * loggingT ) flushAll () []flushSyncWriter {
1236
+ files := make ([]flushSyncWriter , 0 , severity .NumSeverity )
1233
1237
// Flush from fatal down, in case there's trouble flushing.
1234
1238
for s := severity .FatalLog ; s >= severity .InfoLog ; s -- {
1235
1239
file := l .file [s ]
1236
1240
if file != nil {
1237
1241
_ = file .Flush () // ignore error
1238
- _ = file .Sync () // ignore error
1239
1242
}
1243
+ files = append (files , file )
1240
1244
}
1241
1245
if logging .loggerOptions .flush != nil {
1242
1246
logging .loggerOptions .flush ()
1243
1247
}
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
+ }
1244
1259
}
1245
1260
1246
1261
// CopyStandardLogTo arranges for messages written to the Go "log" package's
0 commit comments