Add LogManager shutdown, sink ownership, and drain timeout#12
Merged
Add LogManager shutdown, sink ownership, and drain timeout#12
Conversation
- Add ShutdownAsync/Shutdown with optional timeout for coordinated sink disposal - Auto-register ProcessExit hook on Initialize for safety-net flush (5s timeout) - Add ReconfigureAsync that awaits old sink disposal; sync Reconfigure fires-and-forgets - Add drain timeout to BufferedLogSink (default 30s) to prevent hang on stuck writes - Surface drainTimeout parameter on FileSink, StreamSink, and LogConfigBuilder - Track all sinks in SinkSet for disposal; add DisposeSinksAsync and DisposeAllAsync - Update Reset() to fully dispose sinks (not just monitors) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
ShutdownAsync()/Shutdown()for coordinated sink disposal with optional timeoutReconfigureAsync()that awaits old sink disposal; syncReconfigure()fires-and-forgetsBufferedLogSink(default 30s) to prevent indefinite hangsProcessExithook onInitialize()as a safety net (5s timeout)SinkSetnow tracks all sinks for disposal;LogConfig.DisposeAllAsync()disposes monitors + sinksReset()(test helper) now fully disposes sinks, not just monitorsReason for Change
LogManagerhad no public shutdown path. Buffered sinks (FileSink,StreamSink) silently lost queued entries on process exit.Reconfigure()disposed monitors but leaked old sinks (file handles, drain tasks).BufferedLogSink.DisposeAsync()awaited the drain task with no timeout, risking indefinite hangs on stuck network streams.Impact
Initialize()calls now auto-register aProcessExitsafety-net hookReconfigure()now disposes old sinks (previously leaked) via fire-and-forgetBufferedLogSinknow defaults to 30s drain timeout (previously infinite)Migration Steps
await LogManager.ShutdownAsync()(orLogManager.Shutdown()) at app exit for explicit controlBufferedLogSinksubclasses gain adrainTimeoutconstructor parameter (optional, defaults to 30s)Performance Considerations
Dispatch()is untouchedProcessExithook is a one-time static event registrationTask.WaitAsync+CancellationTokenSourceonly during disposalSecurity Considerations
None.
Breaking Changes
Consumer-facing
Internal
SinkSetconstructor now requires anallSinksarray parameterLogConfig.Reset()now disposes sinks (previously only disposed monitors)BufferedLogSinkdefault drain behavior changed from infinite wait to 30s timeout