Skip to content

Fix behavior when connection drops#56

Merged
nGoline merged 2 commits intomainfrom
bugfix/dispose-transport
Sep 10, 2025
Merged

Fix behavior when connection drops#56
nGoline merged 2 commits intomainfrom
bugfix/dispose-transport

Conversation

@nGoline
Copy link
Copy Markdown
Owner

@nGoline nGoline commented Sep 10, 2025

Closes #55

Add a method to check if the TCP connection is open;
Dispose of the TransportService correctly in case of disconnections;

dispose of the TransportService correctly in case of disconnections;

Signed-off-by: Níckolas Goline <nickolas.goline+github@gmail.com>
@nGoline nGoline requested a review from Copilot September 10, 2025 12:49
@nGoline nGoline self-assigned this Sep 10, 2025
@nGoline nGoline added the bug Something isn't working label Sep 10, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 improves the robustness of connection handling by adding proper socket state detection, enhancing error handling during disconnections, and implementing proper resource disposal patterns.

  • Added an IsSocketConnected() method to detect dropped TCP connections
  • Improved exception handling and resource cleanup in TransportService and MessageService
  • Enhanced connection state validation throughout the handshake and message processing flow

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/NLightning.Node/Program.cs Added global unhandled exception logging
src/NLightning.Infrastructure/Transport/Services/TransportService.cs Added socket connection validation and improved buffer management with ArrayPool
src/NLightning.Infrastructure/Transport/Handshake/States/HandshakeState.cs Minor comment update
src/NLightning.Infrastructure/Protocol/Services/MessageService.cs Enhanced exception handling and thread-safe disposal
src/NLightning.Infrastructure/Node/Services/PeerService.cs Added error handling during initialization
src/NLightning.Infrastructure/Node/Services/PeerCommunicationService.cs Improved disconnection handling and ping service management
src/NLightning.Infrastructure/Node/Factories/PeerServiceFactory.cs Added proper resource disposal on connection failures
src/NLightning.Domain/Protocol/Interfaces/IMessageService.cs Added throwOnException parameter to SendMessageAsync
src/NLightning.Application/Node/Managers/PeerManager.cs Added error handling during peer disconnection

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Níckolas Goline <nickolas.goline+github@gmail.com>
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
NLightning.Application 30% 22% 258
NLightning.Bolt11 88% 82% 498
NLightning.Domain 72% 49% 1556
NLightning.Infrastructure 56% 46% 1003
NLightning.Infrastructure.Bitcoin 56% 50% 466
NLightning.Infrastructure.Persistence 0% 0% 156
NLightning.Infrastructure.Persistence.Postgres 0% 100% 7
NLightning.Infrastructure.Persistence.Sqlite 0% 100% 4
NLightning.Infrastructure.Persistence.SqlServer 0% 100% 7
NLightning.Infrastructure.Repositories 0% 0% 474
NLightning.Infrastructure.Serialization 67% 51% 861
NLightning.Node 10% 12% 211
NLightning.Tests.Utils 84% 50% 19
Summary 44% (6607 / 15010) 46% (1725 / 3753) 5520

@nGoline nGoline merged commit 9850142 into main Sep 10, 2025
4 checks passed
@nGoline nGoline deleted the bugfix/dispose-transport branch September 10, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NLightning crashes after establishing and closing some connections

2 participants