-
Notifications
You must be signed in to change notification settings - Fork 469
fix(printer): properly close output files to prevent data loss #4998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(printer): properly close output files to prevent data loss #4998
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a critical bug where printer Close() methods were not closing their underlying output files, causing intermittent data loss when write buffers weren't flushed before process termination.
Key Changes:
- Implemented proper file closing logic in Close() methods for three printer types (tableEventPrinter, templateEventPrinter, jsonEventPrinter)
- Added nil checks and error logging when closing output files
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4998 +/- ##
=======================================
Coverage ? 29.69%
=======================================
Files ? 234
Lines ? 26086
Branches ? 0
=======================================
Hits ? 7745
Misses ? 17802
Partials ? 539
🚀 New features to boost your workflow:
|
f58226f to
75d2681
Compare
Printer Close() methods now call Sync() to flush OS buffers before process exit. This fixes intermittent test failures where buffered events weren't written to disk during graceful shutdown.
75d2681 to
dbe2a1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| assert.Contains(t, output, `1234567890`, "timestamp should be included") | ||
| } | ||
|
|
||
| // TestPrinterCloseFlusheData tests that Close() calls Sync() to flush buffered data to disk |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'FlushesData' in function name (typo in comment: 'FlusheData').
| // TestPrinterCloseFlusheData tests that Close() calls Sync() to flush buffered data to disk | |
| // TestPrinterCloseFlushesData tests that Close() calls Sync() to flush buffered data to disk |
|
|
||
| func (p tableEventPrinter) Close() { | ||
| // Sync flushes buffered data, ensuring events aren't lost on process exit | ||
| if f, ok := p.out.(*os.File); ok && f != nil { |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nil check f != nil is redundant after a successful type assertion. If the type assertion succeeds, f cannot be nil. Consider simplifying to if f, ok := p.out.(*os.File); ok {.
| if f, ok := p.out.(*os.File); ok && f != nil { | |
| if f, ok := p.out.(*os.File); ok { |
|
|
||
| func (p templateEventPrinter) Close() { | ||
| // Sync flushes buffered data, ensuring events aren't lost on process exit | ||
| if f, ok := p.out.(*os.File); ok && f != nil { |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nil check f != nil is redundant after a successful type assertion. If the type assertion succeeds, f cannot be nil. Consider simplifying to if f, ok := p.out.(*os.File); ok {.
| if f, ok := p.out.(*os.File); ok && f != nil { | |
| if f, ok := p.out.(*os.File); ok { |
|
|
||
| func (p jsonEventPrinter) Close() { | ||
| // Sync flushes buffered data, ensuring events aren't lost on process exit | ||
| if f, ok := p.out.(*os.File); ok && f != nil { |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nil check f != nil is redundant after a successful type assertion. If the type assertion succeeds, f cannot be nil. Consider simplifying to if f, ok := p.out.(*os.File); ok {.
| if f, ok := p.out.(*os.File); ok && f != nil { | |
| if f, ok := p.out.(*os.File); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Feel free to merge after fixing the suggestion from copilot. Thanks
The Close() methods for jsonEventPrinter, templateEventPrinter, and tableEventPrinter were empty stubs that never closed the underlying io.WriteCloser. This caused intermittent test failures when OS write buffers weren't flushed before process termination, resulting in lost events in the output files.
Now all printer types properly close their output files, ensuring buffers are flushed and all events are written to disk.