Skip to content

fix: close file transports before reconfigure to avoid write-after-end - #2645

Open
Yahiro025 wants to merge 5 commits into
winstonjs:masterfrom
Yahiro025:fix/1573-configure-file-transport-write-after-end
Open

Yahiro025 wants to merge 5 commits into
winstonjs:masterfrom
Yahiro025:fix/1573-configure-file-transport-write-after-end

Conversation

@Yahiro025

Copy link
Copy Markdown

Summary

Fixes #1573. On logger.configure({ transports }), close/end existing File transports before clearing and attaching new ones so pending writes never hit an ended stream (Error: write after end).

Test plan

  • Added unit coverage in test/unit/winston/logger.test.js for reconfiguration / close-before-clear behavior
  • Focused logger suite passed in the agent run

Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
Comment thread lib/winston/logger.js Outdated
if (this.transports.length) {
this.transports.forEach(transport => {
if (typeof transport.close === 'function') {
transport.close();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line closes each transport directly, and this.clear() unpipes it, so TransportStream's unpipe handler calls close() a second time. A transport that throws on a repeated close call breaks reconfiguration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — thanks. TransportStream already calls close() from its unpipe handler, so the direct close + clear() path was closing twice.

Pushed 883c6b5: we still end each transport before clear() (keeps the #1573 write-after-end fix), but temporarily hide close so unpipe does not invoke it again. Added a regression test where a second close() throws.

TransportStream calls close() again when a transport is unpiped, so
configure's direct close() ran twice. Hide close() until clear()
finishes so File streams still end before unpipe without a second close.

Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File logging reconfiguration issue (Error: write after end)

2 participants