fix: ensure File transport flushes all data before emitting finish #2594
+111
−0
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.
Fixes #1504 and relates to promptfoo/promptfoo#6511
When you call
logger.end()and thenprocess.exit(), log messages get lost. This has been an open issue since 2018.The problem is that the File transport's
finishevent fires when the internal PassThrough drains, not when the actual file write completes. So you think you're safe to exit, but the OS hasn't finished writing yet.The fix adds a
_final()method (the standard Node.js stream hook for this) that waits for the fs.WriteStream to finish before letting the transport emitfinish.To verify the fix:
Before: ~1 line written. After: all 1001 lines written.
Also added regression tests under "Flushing on end (issue #1504)" in
file.test.js.