-
Notifications
You must be signed in to change notification settings - Fork 19
Fix infinite hang #51
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces timeouts during disposal and write operations to prevent infinite hangs, while also refactoring cancellation token usage and test setups.
- Introduces new CancellationTokenSources (_disposingCts and _forceQuitCts) with configurable write and disposal timeouts.
- Overloads TCPSink and related configuration extensions to support timeout parameters.
- Refactors tests to use freely bound ports and removes duplicate test implementations.
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
Serilog.Sinks.Network/Sinks/UDP/UDPSink.cs | Removed redundant _socket = null assignment in Dispose. |
Serilog.Sinks.Network/Sinks/TCP/TCPSocketWriter.cs | Updated CTS usage, added timeout handling, and refactored reconnection logic. |
Serilog.Sinks.Network/Sinks/TCP/TCPSink.cs | Altered constructor overloads for improved dependency injection. |
Serilog.Sinks.Network/NetworkLoggerConfigurationExtensions.cs | Revised parameter types and added timeout parameters. |
Test Files | Updated tests to use free ports and consolidated UDP/TCP test files for clarity. |
ServerPoller.cs | Improved asynchronous socket handling and added cancellation support. |
PingPonger/Program.cs | Updated TCPSink invocations to include timeout parameters. |
Files not reviewed (1)
- Serilog.Sinks.Network/Serilog.Sinks.Network.csproj: Language not supported
Comments suppressed due to low confidence (1)
Serilog.Sinks.Network/Sinks/TCP/TCPSocketWriter.cs:222
- The null-check for _stream in FlushQueue indicates an unexpected state; consider revisiting the connection lifecycle to ensure _stream is consistently assigned or properly reinitialized.
if (_stream == null)
@@ -49,6 +49,15 @@ public static LoggerConfiguration TCPSink( | |||
return TCPSink(loggerConfiguration, $"tcp://{ipAddress}:{port}", writeTimeoutMs, disposeTimeoutMs, textFormatter, restrictedToMinimumLevel); | |||
} | |||
|
|||
public static LoggerConfiguration TCPSink( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! thank you!
Hi @pauldambra ,
This is the key part we want to upstream!
It adds a timeout on Dispose/Flush so we avoid infinitely hanging.
Changes: