Commit a3a5748
fix: shared TCP connection never recovers from silent connection loss (#354)
Upstream v1.0.x routes every TCP entry through SharedModbusConnection,
whose ensure_connected() trusts pymodbus is_socket_open(). For sync
clients that is just `self.socket is not None`, and pymodbus never
clears the socket on receive timeouts (connection_lost() is a no-op
without an asyncio transport). After a silent drop (gateway reboot,
Wi-Fi dropout, idle NAT timeout) every poll reused the dead socket
forever; only an HA restart recovered.
- SharedModbusConnection.reset(): force-close so the next
ensure_connected() performs a real reconnect (with buffer flush)
- _fetch_data_shared(): on a failed poll, reset + reconnect + retry
once in-poll; reset again if the retry also fails, and on exceptions
- hub write_register/write_registers: drop the socket on transport
level exceptions so service writes self-heal via ensure_connected()
Restores the self-healing the pre-v1.0 per-poll reconnect path had.
Co-authored-by: jekmanis <jekmanis@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 0f5c738 commit a3a5748
2 files changed
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
951 | 951 | | |
952 | 952 | | |
953 | 953 | | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
954 | 972 | | |
955 | 973 | | |
956 | 974 | | |
| |||
960 | 978 | | |
961 | 979 | | |
962 | 980 | | |
| 981 | + | |
963 | 982 | | |
964 | 983 | | |
965 | 984 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
457 | 472 | | |
458 | 473 | | |
459 | 474 | | |
| |||
550 | 565 | | |
551 | 566 | | |
552 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
553 | 571 | | |
554 | 572 | | |
555 | 573 | | |
| |||
567 | 585 | | |
568 | 586 | | |
569 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
570 | 591 | | |
571 | 592 | | |
572 | 593 | | |
| |||
0 commit comments