-
Notifications
You must be signed in to change notification settings - Fork 70
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
Opening and closing a TCP socket to the Modbus slave should work continuously.
Actual behavior (suspected bug)
After opening 5 sockets, it then fails in mb_drv_open.
pdrv_ctx->mb_node_open_count is incremented for each opened connection. But it is never decremented anywhere, not that I can find anyway. Therefore the below check fails, resulting in errors when trying to open new Modbus clients.
if (pdrv_ctx->mb_node_open_count > MB_MAX_FDS) {
goto err;
}
I added a custom message "Too many Modbus nodes open" to show this. The log below shows this condition.
Error logs or terminal output
D (81254) mb_port.tcp.slave: loop:0x3fcbb1f0 mbs_on_timeout: fd: -1
D (81346) mb_driver: 0x3fcbb1f0, listen_sock is active.
I (81346) port.utils: Socket (#60), accept client connection from address[port]: 192.168.4.2[55907]
D (81350) mb_driver: port_accept_connection: 60
D (81354) mb_driver: 0x3fcbb1f0, open vfd: 0, sl_addr: 00, node: 192.168.4.2:55907
D (81358) mb_driver: mb_drv_open: addr_info.fd=60, fd=0
E (81366) mb_driver: Too many Modbus nodes open!
E (81370) mb_driver: 0x3fcbb1f0, unable to open node: 192.168.4.2
D (81578) mb_driver: 0x3fcbb1f0, fd event get: 0x100:-1, |MB_EVENT_TIMEOUT
D (81578) event: running post loop:0x3fcbb1f0:256 with handler 0x4200e698 and context 0x3fcbd064 on loop 0x3fcbb5dc
--- 0x4200e698: mbs_on_timeout at C:/Users/James/Documents/Dev/basic/managed_components/espressif__esp-modbus/modbus/mb_ports/tcp/port_tcp_slave.c:592Steps to reproduce the behavior
TCP example slave.
2. Connect and reconnect using Modbus client like Simply Modbus.
3. Perform this multiple times in a row and eventually the client won't be able to connect.
Project release version
latest
System architecture
Intel/AMD 64-bit (modern PC, older Mac)
Operating system
Windows
Operating system version
Windows 10
Shell
ZSH
Additional context
Using ESP-IDF V5.4.0 with WiFi AP setup. ESP32-S3