Skip to content

Closing connection on any error#126

Open
alexjoedt wants to merge 6 commits intomasterfrom
fix/connection-lifecycle-error-handling
Open

Closing connection on any error#126
alexjoedt wants to merge 6 commits intomasterfrom
fix/connection-lifecycle-error-handling

Conversation

@alexjoedt
Copy link
Contributor

@alexjoedt alexjoedt commented Mar 23, 2026

This pull request updates the error handling logic in the tcpclient.go file for the Modbus TCP client. The main change is to simplify and strengthen the handling of write errors when sending data over the TCP connection: now, the connection is closed on any write error, not just specific ones like EPIPE. This ensures the client always recovers cleanly from any corrupted or lost connection state.

Improved error handling for TCP writes:

  • The Send method now closes the TCP connection on any write error, not just EPIPE, to ensure the client recovers from all possible connection issues and avoids protocol desynchronization. This change also improves the clarity of comments explaining why this is necessary for a request/response protocol like Modbus.

Code cleanup:

  • The unused import of the errors package was removed from tcpclient.go.

Resolves #97

@alexjoedt alexjoedt added the bug Something isn't working label Mar 23, 2026
@alexjoedt alexjoedt requested a review from ftobusch March 23, 2026 09:59
@alexjoedt alexjoedt self-assigned this Mar 23, 2026
@alexjoedt alexjoedt marked this pull request as ready for review March 23, 2026 10:01
@alexjoedt alexjoedt force-pushed the fix/connection-lifecycle-error-handling branch from 190c4e7 to cef2fb3 Compare March 23, 2026 10:50
@alexjoedt alexjoedt force-pushed the fix/connection-lifecycle-error-handling branch from cef2fb3 to 42f02e8 Compare March 23, 2026 10:51
@andig
Copy link
Contributor

andig commented Mar 23, 2026

Closing on every error is what evcc has been successfully doing for a long time.

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.

TCP: better handling of server-closed connections

2 participants