Repository navigation
fix: flush and sync all router outputs before closing any - #17
Merged
Merged
Conversation
A writer can be owned by one route through OutputCloser and also written by another route through Output. The close function used to flush, sync and close each output in turn, so when the owning route came first the writer was closed and then synced again, and close reported a "file already closed" error although everything had been written. Close now flushes and syncs every output first and closes the owned writers after that. The OutputCloser documentation now says that a shared writer is closed once per OutputCloser.
ssgreg
force-pushed
the
fix/router-close-once
branch
from
December 4, 2026 06:33
36a90d9 to
faa32b1
Compare
Contributor
Author
|
Reworked: dropped the pointer-identity dedupe of shared writers and the stored close result. Ownership is already explicit through |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
A writer can be owned by one route and only written by another:
The close function flushed, synced and closed each output in turn. The first output closed
f, the second synced it again, and close returned an error although every entry had been written. With the routes in the other order the same setup closed cleanly.Change
OutputCloser.OutputCloserdoc says that a writer shared by several routes is closed once perOutputCloser, so it should go toOutputCloseronce and toOutputelsewhere.Testing
TestRouterCloseSyncsSharedWriterBeforeClosingItbuilds the setup above on a real file and expects close to return nil and the file to hold both lines. Onmainit fails withfile already closed.go test -race ./...andgolangci-lint runpass. The write path is unchanged;RealisticPipeline, six interleaved rounds againstmain, shows no statistically significant change in time,B/oporallocs/op.