Repository navigation
Conversation
|
Force-pushed af0e66d -> 6fe4158 and split. Closing a writer shared by several outputs once, and keeping the close result, moved to #17; this PR now only adds the panics on use after close and is based on #17, since without it the second output's Flush would panic on a shared SlabWriter. The code of both PRs together is the same as before. |
36a90d9 to
faa32b1
Compare
|
Rebased onto the reworked #17. The shared |
Writing to a SlabWriter after Close hung once its slab pool ran dry, with the writer's mutex held, so every goroutine that logged after it hung too; with DropOnFull the entries were dropped without a trace. A router kept accepting entries after its close function ran. SlabWriter.Write and Flush and the router's Handle now panic after close, so a shutdown ordering bug shows up as a stack trace pointing at the late writer.
|
Rebased onto |
Needs #17 (merged), which flushes and syncs every router output before closing any. Without it, a
SlabWritergiven toOutputCloserin one route and toOutputin a later one would now panic onFlushduring close.Problem
Writing to a
SlabWriterafterCloseneither panics nor fails:The I/O goroutine is gone, so filled slabs are never returned. Once the pool is empty,
Writewaits for a free slab forever while holding the writer's mutex, and every goroutine that logs after that hangs too. WithDropOnFullthe same entries are dropped without a trace. A router keeps accepting entries after its close function ran.Change
SlabWriter.WriteandSlabWriter.Flushpanic afterClose. The check reads a flag under the mutexWritealready takes, so the hot path gets no new synchronization. A shutdown ordering bug now shows up as a stack trace pointing at the late writer.Handlepanics after close. This is one atomic load per entry.Builddoc says to stop logging before calling close: the flag catches aHandlethat starts after close, it does not wait for one already in progress. No lock is added to the per-entry path.Testing
New tests in
lifecycle_test.go:TestSlabWriterWriteAfterClosePanics, blocking andDropOnFullmodes.main: blocks, fails after the 5 s guard. Branch: panics withlogf: SlabWriter.Write after Close.TestSlabWriterFlushAfterClosePanics.main: no panic.TestRouterHandleAfterClosePanics.main: the entry is written.TestRouterCloseFlushesSharedSlabWriterBeforeClosingIt: oneSlabWriterinOutputCloserof the first route andOutputof the second; close returns nil and both entries reach the output. It guards the newFlushpanic against the close order.go test -race ./...andgolangci-lint run(v2, repo config) pass.Benchmarks were run on the previous revision of this branch (6fe4158 against
mainat bea5187).SlabWriterand the router'sHandleare the same in the current revision. Each was built once and run in ten interleaved rounds of the package'sSlab*andRealisticPipelinebenchmarks and thebenchmarksmodule'sLogf_TwoScalars,Logf_Router_NoFieldsandLogf_RouterSlab_NoFields, compared withbenchstat. The machine was loaded (load average about 12 on 15 cores), so the spread is wide.B/opandallocs/opare unchanged. One row is marked significant,SlabBufferFragmentationWorstCaseat +4.5% (p=0.045, ±29%); every otherSlabWriterrow, which takes the same check, shows no change, so we read it as noise. The router rows show no change.