-
Notifications
You must be signed in to change notification settings - Fork 11
Fix TcpListener disposal in TcpClientNmeaStreamReaderTests #268
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 TcpListener disposal in TcpClientNmeaStreamReaderTests #268
Conversation
Co-authored-by: HowardvanRooijen <[email protected]>
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 refactors 11 test methods in TcpClientNmeaStreamReaderTests to ensure proper cleanup of TcpListener resources, even when exceptions occur during test setup. The refactoring prevents potential resource leaks by guaranteeing that Stop() is safely called in all scenarios.
Key Changes:
- Moved
TcpListenerinitialization from outside try blocks to inside them - Changed listener declarations to nullable type (
TcpListener?) initialized to null - Updated finally blocks to use null-conditional operator (
listener?.Stop()) for safe cleanup
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
|
|
||
| try | ||
| { | ||
| listener = new(IPAddress.Loopback, 0); |
Copilot
AI
Nov 29, 2025
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.
Disposable 'TcpListener' is created but not disposed.
TcpListenerinstances were created outside try blocks, meaningStop()wouldn't be called if exceptions occurred during setup.Changes
TcpListenerto ensure proper cleanuplistener?.Stop()for safe disposalBefore:
After:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.