Skip to content
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

fix: only flush the queue after open if not already writing #25

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

nlf
Copy link
Contributor

@nlf nlf commented Jan 26, 2023

this impacted code that followed a pattern like the following:

const s = fsm.createWriteStream(p)
s.on('open', () => {
  s.write('hello ')
  s.write('human')
  s.end()
})

since emitting the open event is synchronous and calls all of its handlers synchronously, the first write starts immediately and the second write is queued, then the _onopen method calls _flush() which races the _onwrite call from the first write. by only calling _flush if we're not already writing, we avoid this situation where flush gets called twice and we prevent lost data.

for npm/statusboard#631
closes #24

@nlf nlf requested a review from a team as a code owner January 26, 2023 21:07
@nlf nlf merged commit 97116ba into main Jan 30, 2023
@nlf nlf deleted the nlf/fix-race branch January 30, 2023 16:58
@github-actions github-actions bot mentioned this pull request Jan 30, 2023
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.

flaky tests: async after open
2 participants