Flush buffer again after first "flush" event #447
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In file transport, before the
FileStream
is opened, logs are buffered to_buffer
.Once the
FileStream
is opened, file transport will flush_buffer
to disk and wait for the firstdrain
event from the stream. After thedrain
event is received,_buffer
will be decommissioned and subsequent write will direct to theFileStream
itself.There are race condition when the logs are written inbetween the
flush
call and thedrain
event. Logs written inbetween them will still be stored in_buffer
(becauseself.opening
is stilltrue
). Because we did not flush the_buffer
again afterdrain
, some logs could be orphaned there forever.The fix is to flush the
_buffer
again after thedrain
event is received.