File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 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 {
369369
370370// flush flushes all logs of severity threshold or greater.
371371func (s * fileSink ) flush (threshold logsink.Severity ) error {
372- s .mu .Lock ()
373- defer s .mu .Unlock ()
374-
375372 var firstErr error
376373 updateErr := func (err error ) {
377374 if err != nil && firstErr == nil {
378375 firstErr = err
379376 }
380377 }
381378
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+ }
388391 }
392+ }()
393+
394+ for _ , file := range files {
395+ updateErr (file .Sync ())
389396 }
390397
391398 return firstErr
You can’t perform that action at this time.
0 commit comments