File tree 1 file changed +16
-9
lines changed
1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -369,23 +369,30 @@ func (s *fileSink) Flush() error {
369
369
370
370
// flush flushes all logs of severity threshold or greater.
371
371
func (s * fileSink ) flush (threshold logsink.Severity ) error {
372
- s .mu .Lock ()
373
- defer s .mu .Unlock ()
374
-
375
372
var firstErr error
376
373
updateErr := func (err error ) {
377
374
if err != nil && firstErr == nil {
378
375
firstErr = err
379
376
}
380
377
}
381
378
382
- // Flush from fatal down, in case there's trouble flushing.
383
- for sev := logsink .Fatal ; sev >= threshold ; sev -- {
384
- file := s .file [sev ]
385
- if file != nil {
386
- updateErr (file .Flush ())
387
- updateErr (file .Sync ())
379
+ // Remember where we flushed, so we can call sync without holding
380
+ // the lock.
381
+ var files []flushSyncWriter
382
+ func () {
383
+ s .mu .Lock ()
384
+ defer s .mu .Unlock ()
385
+ // Flush from fatal down, in case there's trouble flushing.
386
+ for sev := logsink .Fatal ; sev >= threshold ; sev -- {
387
+ if file := s .file [sev ]; file != nil {
388
+ updateErr (file .Flush ())
389
+ files = append (files , file )
390
+ }
388
391
}
392
+ }()
393
+
394
+ for _ , file := range files {
395
+ updateErr (file .Sync ())
389
396
}
390
397
391
398
return firstErr
You can’t perform that action at this time.
0 commit comments