Repository navigation
TCP Master: fails to reconnect to slave using IP after ethernet reconnect (EPROT-62) #167
Copy link
Copy link
Closed
Closed
Copy link
Description
Checklist
- Checked the issue tracker for similar issues to ensure this is not a duplicate
- Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
- Tested with the latest version to ensure the issue hasn't been fixed
How often does this bug occurs?
always
Expected behavior
- MB TCP Master should automatically recover after ETH link loss and reconnection
- after ETH reconntion, Master should:
- re-init TCP connection to slave
- resume polling without requiring reboot
Actual behavior (suspected bug)
When slave is defined using static IPV4 address 01;192.168.4.113;1502:
- Initial connection and polling work correctly after boot
- After ETH cable removal and reconnection:
- device connects to the network successfully
- MB TCP Master doesn't connect to the slave
- polling keeps failing
When using mDNS hostname for slave 01;mb_slave_tcp_01;1502:
- device connects to the network successfully
- MB TCP Master connects to slave and polls successfully
Error logs or terminal output
using static IPV4 address `01;192.168.4.187;1502`:
I (1194) esp_eth.netif.netif_glue: 24:xx:c3:xx:23:xx
I (1194) esp_eth.netif.netif_glue: ethernet attached to netif
I (2884) MB_TCP: Main Init
I (2894) main_task: Returned from app_main()
I (5194) esp_netif_handlers: eth ip: 192.168.4.187, mask: 255.255.255.0, gw: 192.168.4.1
I (5604) port.utils: mdns delegate hostname set to: [mb_master_tcp_00]
I (5604) port.utils: IP: 192.168.4.187
I (5604) port.utils: GW: 192.168.4.1
I (5604) port.utils: NETMASK: 255.255.255.0
D (5614) mb_object.master: created object mbm_tcp#0x3ffd35d8
I (5614) mbc_tcp.master: mb found config for cid #0, uid=1.
I (5624) MB_TCP: Modbus master stack initialized...
I (5634) mb_port.tcp.master: 0x3ffd801c, slave: #0, sock:57, IP: 192.168.4.113, is connected.
I (5634) mb_port.tcp.master: 0x3ffd801c, Connected: 1, 1, start polling.
D (5644) mb_object.master: 0x3ffd35d8:EV_READY
D (8644) mb_object.master: 0x3ffd35d8: Unexpected event 0x02 or timeout?
D (10694) mb_object.master: 0x3ffd35d8:EV_FRAME_SENT
D (10794) mb_object.master: 0x3ffd35d8:EV_FRAME_RECEIVED
D (10794) mb_object.master: 0x3ffd35d8, frame data received successfully, (0).
D (10794) mb_object.master: 0x3ffd35d8:EV_EXECUTE
D (10804) mb_object.master: 0x3ffd35d8: function (0x2), invoke handler.
D (10804) mb_object.master: 0x3ffd35d8, set event EV_ERROR_OK
D (10814) mb_object.master: 0x3ffd35d8:EV_ERROR_PROCESS
D (10824) mb_object.master: 0x3ffd35d8, transaction processing time(us) = 124652
D (10824) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35d8 Good response for get cid(0) = ESP_OK
- ETH Link Down
W (14754) mb_port.tcp.master: 0x3ffd801c, node #0, socket(#57)(192.168.4.113), error handling.
E (14754) mb_port.tcp.master: Node: 0, try to repair lost connection, err= -11
E (14754) port.utils: Socket(#-1)(192.168.4.113), fcntl() call error=9
E (14764) mb_port.tcp.master: Modbus connection phase, slave: 0 (192.168.4.113), connection error (-11).
W (15834) mbc_tcp.master: 0x3ffd35d8 Try to send request for cid #0 with uid = 1, node is disconnected.
E (15834) mb_port.tcp.master: mbm_port_tcp_send_data(260): The node UID #1, is not connected.
E (15834) mb_object.master: 0x3ffd35d8, frame send error. 5
D (15844) mb_object.master: 0x3ffd35d8:EV_ERROR_PROCESS
D (15844) mb_object.master: 0x3ffd35d8, transaction processing time(us) = 11231
D (15854) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35d8 Bad response to get cid(0) = ESP_ERR_TIMEOUT
E (15864) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
D (18854) mb_object.master: 0x3ffd35d8: Unexpected event 0x40 or timeout?
W (20884) mbc_tcp.master: 0x3ffd35d8 Try to send request for cid #0 with uid = 1, node is disconnected.
E (20884) mb_port.tcp.master: mbm_port_tcp_send_data(260): The node UID #1, is not connected.
E (20884) mb_object.master: 0x3ffd35d8, frame send error. 5
D (20894) mb_object.master: 0x3ffd35d8:EV_ERROR_PROCESS
D (20894) mb_object.master: 0x3ffd35d8, transaction processing time(us) = 11274
D (20904) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35d8 Bad response to get cid(0) = ESP_ERR_TIMEOUT
E (20914) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
- ETH Link Up (Cable reconencted)
I (23694) esp_netif_handlers: eth ip: 192.168.4.187, mask: 255.255.255.0, gw: 192.168.4.1
D (23904) mb_object.master: 0x3ffd35d8: Unexpected event 0x40 or timeout?
W (25934) mbc_tcp.master: 0x3ffd35d8 Try to send request for cid #0 with uid = 1, node is disconnected.
E (25934) mb_port.tcp.master: mbm_port_tcp_send_data(260): The node UID #1, is not connected.
E (25934) mb_object.master: 0x3ffd35d8, frame send error. 5
D (25944) mb_object.master: 0x3ffd35d8:EV_ERROR_PROCESS
D (25944) mb_object.master: 0x3ffd35d8, transaction processing time(us) = 11206
D (25954) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35d8 Bad response to get cid(0) = ESP_ERR_TIMEOUT
E (25964) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
D (28954) mb_object.master: 0x3ffd35d8: Unexpected event 0x40 or timeout?
W (30984) mbc_tcp.master: 0x3ffd35d8 Try to send request for cid #0 with uid = 1, node is disconnected.
E (30984) mb_port.tcp.master: mbm_port_tcp_send_data(260): The node UID #1, is not connected.
E (30984) mb_object.master: 0x3ffd35d8, frame send error. 5
D (30994) mb_object.master: 0x3ffd35d8:EV_ERROR_PROCESS
D (30994) mb_object.master: 0x3ffd35d8, transaction processing time(us) = 11214
D (31004) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35d8 Bad response to get cid(0) = ESP_ERR_TIMEOUT
E (31014) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
D (34004) mb_object.master: 0x3ffd35d8: Unexpected event 0x40 or timeout?
W (36034) mbc_tcp.master: 0x3ffd35d8 Try to send request for cid #0 with uid = 1, node is disconnected.
E (36034) mb_port.tcp.master: mbm_port_tcp_send_data(260): The node UID #1, is not connected.
E (36034) mb_object.master: 0x3ffd35d8, frame send error. 5
D (36044) mb_object.master: 0x3ffd35d8:EV_ERROR_PROCESS
D (36044) mb_object.master: 0x3ffd35d8, transaction processing time(us) = 11266
D (36054) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35d8 Bad response to get cid(0) = ESP_ERR_TIMEOUT
---
using mDNS hostname for slave `01;mb_slave_tcp_01;1502`:
I (1156) esp_eth.netif.netif_glue: 24:xx:c3:xx:23:xx
I (1156) esp_eth.netif.netif_glue: ethernet attached to netif
I (2946) MB_TCP: Main Init
I (2946) main_task: Returned from app_main()
I (4256) esp_netif_handlers: eth ip: 192.168.4.187, mask: 255.255.255.0, gw: 192.168.4.1
I (4666) port.utils: mdns delegate hostname set to: [mb_master_tcp_00]
I (4666) port.utils: IP: 192.168.4.187
I (4666) port.utils: GW: 192.168.4.1
I (4666) port.utils: NETMASK: 255.255.255.0
D (4676) mb_object.master: created object mbm_tcp#0x3ffd35b8
I (4676) mbc_tcp.master: mb found config for cid #0, uid=1.
I (4686) MB_TCP: Modbus master stack initialized...
D (4696) mb_object.master: 0x3ffd35b8:EV_READY
I (4826) mb_port.tcp.master: 0x3ffd3a24, slave: 0, resolved with IP:192.168.4.113.
I (4836) mb_port.tcp.master: 0x3ffd3a24, slave: #0, sock:57, IP: 192.168.4.113, is connected.
I (4836) mb_port.tcp.master: 0x3ffd3a24, Connected: 1, 1, start polling.
D (7696) mb_object.master: 0x3ffd35b8: Unexpected event 0x02 or timeout?
D (9746) mb_object.master: 0x3ffd35b8:EV_FRAME_SENT
D (9846) mb_object.master: 0x3ffd35b8:EV_FRAME_RECEIVED
D (9856) mb_object.master: 0x3ffd35b8, frame data received successfully, (0).
D (9856) mb_object.master: 0x3ffd35b8:EV_EXECUTE
D (9856) mb_object.master: 0x3ffd35b8: function (0x2), invoke handler.
D (9866) mb_object.master: 0x3ffd35b8, set event EV_ERROR_OK
D (9866) mb_object.master: 0x3ffd35b8:EV_ERROR_PROCESS
D (9876) mb_object.master: 0x3ffd35b8, transaction processing time(us) = 126465
D (9876) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35b8 Good response for get cid(0) = ESP_OK
D (12876) mb_object.master: 0x3ffd35b8: Unexpected event 0x40 or timeout?
D (14886) mb_object.master: 0x3ffd35b8:EV_FRAME_SENT
D (14996) mb_object.master: 0x3ffd35b8:EV_FRAME_RECEIVED
D (14996) mb_object.master: 0x3ffd35b8, frame data received successfully, (0).
D (14996) mb_object.master: 0x3ffd35b8:EV_EXECUTE
D (14996) mb_object.master: 0x3ffd35b8: function (0x2), invoke handler.
D (15006) mb_object.master: 0x3ffd35b8, set event EV_ERROR_OK
D (15006) mb_object.master: 0x3ffd35b8:EV_ERROR_PROCESS
D (15016) mb_object.master: 0x3ffd35b8, transaction processing time(us) = 127513
D (15026) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35b8 Good response for get cid(0) = ESP_OK
- ETH Link Down
W (402766) mb_port.tcp.master: 0x3ffd3a24, node #0, socket(#57)(192.168.4.113), error handling.
E (402766) mb_port.tcp.master: Node: 0, try to repair lost connection, err= -11
D (403326) mb_object.master: 0x3ffd35b8: Unexpected event 0x40 or timeout?
W (405336) mbc_tcp.master: 0x3ffd35b8 Try to send request for cid #0 with uid = 1, node is disconnected.
E (405336) mb_port.tcp.master: mbm_port_tcp_send_data(260): The node UID #1, is not connected.
E (405336) mb_object.master: 0x3ffd35b8, frame send error. 5
D (405346) mb_object.master: 0x3ffd35b8:EV_ERROR_PROCESS
D (405346) mb_object.master: 0x3ffd35b8, transaction processing time(us) = 11483
D (405356) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35b8 Bad response to get cid(0) = ESP_ERR_TIMEOUT
E (405366) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
D (408356) mb_object.master: 0x3ffd35b8: Unexpected event 0x40 or timeout?
- ETH Link Up (Cable reconencted)
I (408756) Connection Handler: ETH HW Addr 24:XX:C3:XX:23:XX
I (409756) esp_netif_handlers: eth ip: 192.168.4.187, mask: 255.255.255.0, gw: 192.168.4.1
I (409926) mb_port.tcp.master: 0x3ffd3a24, slave: 0, resolved with IP:192.168.4.113.
I (409936) mb_port.tcp.master: 0x3ffd3a24, slave: #0, sock:57, IP: 192.168.4.113, is connected.
I (409936) mb_port.tcp.master: 0x3ffd3a24, Connected: 1, 1, start polling.
D (410386) mb_object.master: 0x3ffd35b8:EV_FRAME_SENT
D (410486) mb_object.master: 0x3ffd35b8:EV_FRAME_RECEIVED
D (410486) mb_object.master: 0x3ffd35b8, frame data received successfully, (0).
D (410486) mb_object.master: 0x3ffd35b8:EV_EXECUTE
D (410496) mb_object.master: 0x3ffd35b8: function (0x2), invoke handler.
D (410496) mb_object.master: 0x3ffd35b8, set event EV_ERROR_OK
D (410506) mb_object.master: 0x3ffd35b8:EV_ERROR_PROCESS
D (410506) mb_object.master: 0x3ffd35b8, transaction processing time(us) = 123279
D (410516) mbc_tcp.master: mbc_tcp_master_get_parameter: 0x3ffd35b8 Good response for get cid(0) = ESP_OKSteps to reproduce the behavior
- Configure MB TCP Master with slave address using static IP
- Boot with ETH connected
- Master connects to slave and polling works correctly
- Disconnect ETH cable
- Reconnect ETH cable
- Device reconnects to Network but MB TCP Master fails to connect to slave
Project release version
v2.1.2
System architecture
Intel/AMD 64-bit (modern PC, older Mac)
Operating system
Linux
Operating system version
Ubuntu 24.04
Shell
ZSH
Additional context
- Alex please correct me if i'm wrong here! This case happens as the socket gets closed and is not opened again (same can be seen in static IP logs).
- for now to make it work for my use case:
- i stop the stack (mbc_master_stop) on ETH LINK DOWN (cable plugged out)
- start the stack (mbc_master_start) on ETH LINK UP (cable plugged in [reconn])
- This is not a good approach IMO and i am unable to think of a better approach. Would appreciate your view on this !!! 💯
Reactions are currently unavailable
Activity
[-]TCP Master: fails to reconnect to slave using IP after ethernet reconnect[/-][+]TCP Master: fails to reconnect to slave using IP after ethernet reconnect (EPROT-62)[/+]alisitsyn commentedon Apr 10, 2026
@ram-bt ,
Thank you for this report.
I agree with you and remember I was testing this and this aspect was working just fine in my tests for some previous versions. esp-modbus got a lot of updates and they apply to overall functionality. I will try to reproduce ASAP and then will fix this accordingly. The issue will follow the formal process and I will inform you about the status.
There is some aspect of handling that needs to be verified. I need to check this and fix a bit later.
If it is possible, please consider to send the reproducible example and the sdkconfig file.
Thanks.
alisitsyn commentedon Apr 16, 2026
Hi @ram-bt ,
I just checked the scenario you provided above. As per my results when the Ethernet cable reconnected the Modbus master still be able to repair the connection and restart polling. My experiments are preformed on two ESP32-Ethernet-Kit_A_V1.2 (master + slave) connected to Modbus segment over Ethernet connection. The code is from latest main branch of the project.
The log of master is attached:
esp32_eth_modbus_communication.log
In the log I comment all the stages like below:
"<<<<<<<<<<<< Connected to Modbus stale successfully, start polling"
According to my test the Modbus master can re-establish communication with slave after cable re-connection.
I use the default ethernet configuration in the kconfig:
I think this issue requires more information about your project and some details of the configuration.
Thanks.
ram-bt commentedon Apr 16, 2026
Hi Alex, Sorry for the delay. I'm facing the same issue as #161 and after using the component from
bugfix/improve_event_handling_path_timingi'm having some problems which i will mention under #162 .Let me send you a reproducible example in a bit. I will share my sdkconfig here.
=>
=> I am using LAN8720A-CP for PHY and using MAC of ESP32 (What more details should i provide here?)
=> sdkconfig.zip
=> I have a simple setup where MB TCP Slave & Master share the same network. I have set 192.168.4.113 as static IP for the slave. I have 2 I/O [14,15] set as input on slave and master polls this slave every 5 seconds. My main priority is (considering stable network) communication between Master and Slave. (What more details should i provide here?)
ram-bt commentedon Apr 16, 2026
I will pull the component from
mainand verify the same once.alisitsyn commentedon Apr 16, 2026
Hi @ram-bt,
Thanks for update. Before continue with this and providing the concrete recommendations could you try the following settings:
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=3000, check thembm_opts->comm_opts.tcp_opts.response_tout_ms = 3000(overrides the value from define above),FMB_TCP_KEEP_ALIVE_TOUT_SEC=2000,Recompile and restart your tests.
It seems in your tests you get other race condition related to the issue, the fix is in progress but is not merged. Please try to not exceed the
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=3000!ram-bt commentedon Apr 16, 2026
Thanks for the quick response alex.
I have kept this field empty so that it takes the default value, and instead i try to use the queues waittime to poll after 5 seconds (let me share the example real quick for you to see)
I have also modified TCP keep alive (
FMB_TCP_KEEP_ALIVE_TOUT_SEC) to 2 secBut i still notice the same issue:
alisitsyn commentedon Apr 16, 2026
@ram-bt ,
The error says "Bad file descriptor" because the connection was closed in the error handler then we try to resolve the node address and reconnect. The
E (310685) mb_port.tcp.master: Modbus connection phase, slave: 0 (192.168.4.113), connection error (-11).says that the stack tries to connect to the slave node but for some reason can not do this because socket API returns the connection error. This is why the node is kept disconnectedW (313675) mbc_tcp.master: 0x3ffafb98 Try to send request for cid #0 with uid = 1, node is disconnected.and the master reports about it and timed out transactionE (313665) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x103) (ESP_ERR_INVALID_STATE). From the stack handling standpoint everything works just as expected but the master can not reconnect to the slave. This is network issue and also its event queue specific aspect. This is expected behavior of master when it gets the connection error and it does not try to reconnect immediately, can do this only after timeout.Please send me more log. This looks strange.
ram-bt commentedon Apr 16, 2026
Sure Alex. Will do
alisitsyn commentedon Apr 16, 2026
@ram-bt,
I need to inform that from tomorrow I will not be able to respond at least one week. I will return to it ASAP. Please keep me posted if you have updates. I will check the results when possible.
Thank you for understanding.
ram-bt commentedon Apr 16, 2026
No worries. I will share updates here.
8 remaining items
ram-bt commentedon May 20, 2026
Alex, I have a ETH kit(it is a lil older [V1.1 WROVER-B]) and the same issue can be reproduced on it from my end
ram-bt commentedon May 20, 2026
Let me know if i should share any logs/build for the same
alisitsyn commentedon May 20, 2026
Yes, I can reproduce this partially at least and have some findings. I am looking to the ways for correct fix for the issue.
alisitsyn commentedon May 21, 2026
@ram-bt ,
Current simple way to fix the issue is in PR #173. There are others (in progress) and PR will be updated.
ram-bt commentedon May 21, 2026
Alex, appreciate the quick fix! I will test at my end and get back to you
alisitsyn commentedon May 25, 2026
@ram-bt ,
Just a reminder: Please check this when possible. This should fix your issue.
Thanks.
alisitsyn commentedon Jul 2, 2026
Merged to main with commit: c1a4193