letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.25k stars 2.2k forks source link

Easy ESP on esp8266 drops TCP connection to Serial server if there is another connection #3035

Open std10k opened 4 years ago

std10k commented 4 years ago

Easy ESP drops TCP connection to the serial server port if there is another connection to that port which times out or gets terminated otherwise.

I have esp8266 with cc2530 zigbee coordinator connected over GPIO. Zigbee2mqtt software connects to the serial port (1775 in my case) and works fine until another TCP connection occurs to that port. I noticed is as i had a monitoring system (PRTG) that was checking the port for availability every 5 minutes, and every 5 minutes (or 1 minute, depending on probe settings, but always consistently) Zigbee2mqtt's connection will get terminated causing it to restart. Telnet on port 1775 from windows seems to have the same effect.

Expected behavior

Perhaps EasyESP should not kill all connections like this as there is no way to control access by individual port (i believe), which means that with this issue present, any random connection can destabilise EasyESP and cause the client software to crash (unless it can handle tcp reconnect, which zigbee shepherd for example cannot)

Steps to reproduce

1) esp8266 with serial server 2) establish persistent connection to the serial server over TCP from the expected client 3) get another system like PRTG to connect to the TCP port of the serial server 4) the first connection gets dropped.

am experiencing it with the latest mega build from April 2020, but previously had the same behavior with "stable build 120" so it seems to be carrying over.

Build:⋄ 20105 - Mega System Libraries:⋄ ESP82xx Core 3d128e5c, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support Git Build:⋄ mega-20200410 Plugin Count:⋄ 46 [Normal] Build Time:⋄ Apr 10 2020 19:50:11 Binary Filename:⋄ ESP_Easy_mega-20200410_normal_ESP8266_4M1M.bin

TD-er commented 4 years ago

Just a note of the first thing that comes to mind right now, so it is more of a reminder for me to check it. There is a fixed number of max. open connections. Maybe we're hitting this limit?

std10k commented 4 years ago

How can i check that setting? can't see anything obvious in the settings. It not that a new connection cannot be established, it can be, but it causes for the existing connection to get dropped. Though it could be that only the latest one survives. In my environment there should be no other connections, so it would have to be set to '1' to cause the issue.

TD-er commented 4 years ago

It is somewhere around 5 if memory serves me well.

But I can imagine if it is a connection made by a WiFiClient object, that it can only handle a single active connection.

uzi18 commented 4 years ago

first try change port to 80 in your monitoring system

sincze commented 5 months ago

Do we have an idea about the amount of simultaneous sessions the esp8266 and Communication Server is able to provide with the current ESPEasy release?? (Asking for a friend :) )

Client 1 2024-04-01 20:04:53.755 [ac1fd200] Status: Water / Smart Meter: disconnected 2024-04-01 20:04:53.755 [ac1fd200] Status: Water / Smart Meter: Connection reset!

Client 2 2024-04-01 20:04:54.150 Status: Water / Smart Meter: Meter reports as ESMR 5.0 2024-04-01 20:04:54.150 Status: Water / Smart Meter: Found gas meter on M-Bus channel 1 2024-04-01 20:04:58.565 Status: Water / Smart Meter: Gas meter clock is 2 seconds ahead - wait for my clock to catch up 2024-04-01 20:05:23.771 Status: Water / Smart Meter: disconnected 2024-04-01 20:05:23.771 Status: Water / Smart Meter: Connection reset!

Client 1 2024-04-01 20:05:23.760 [ac1fd200] Status: Water / Smart Meter: connected to: 192.168..:10004 2024-04-01 20:05:24.028 [ac1fd200] Status: Water / Smart Meter: Meter reports as ESMR 5.0 2024-04-01 20:05:24.028 [ac1fd200] Status: Water / Smart Meter: Found gas meter on M-Bus channel 1

So 1 disconnects when the other connects and vice versa. I would have expected at least 2 simultaneous connections,

TD-er commented 5 months ago

Depends on other connections as well. If I'm not mistaken, the number of open connections is 5. But this is shared among all TCP connections. (maybe also UDP, not 100% sure)

sincze commented 5 months ago

Ah those other connections. mmmm Any suggestions on how I can figure this out ;-)

tonhuisman commented 5 months ago

I expect that the serial server, and other plugins that allow an IP connection from outside, are/act like point-to-point connections, accepting only 1 client simultaneously.

sincze commented 5 months ago

Don't know if it is really the case. Assuming it is based on Ser2Net, multiple connections should be possible from Ser2Net 3.2+ https://github.com/cminyard/ser2net

https://github.com/cminyard/ser2net/blob/master/ser2net.yaml.5 On a port to allow more than one connection at a time to the same serial port. These connections will share all the settings. You cannot have two separate TCP ports connect to the same port at the same time.

So the happy flow would be in my case 2 IP's connecting to the same port 10004.

Sándor

On Mon, Apr 1, 2024 at 10:32 PM Ton Huisman @.***> wrote:

I expect that the serial server, and other plugins that allow an IP connection from outside, are/act like point-to-point connections, accepting only 1 client simultaneously.

— Reply to this email directly, view it on GitHub https://github.com/letscontrolit/ESPEasy/issues/3035#issuecomment-2030507670, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMCHTM2K4RZOQU77ID6YVLY3G77XAVCNFSM4MREIBIKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBTGA2TANZWG4YA . You are receiving this because you commented.Message ID: @.***>

TD-er commented 5 months ago

As far as I can see, Ser2Net isn't for ESP/Arduino platforms. We are limited by the limits of LWIP.

Not sure what should be done to let LWIP does support multiple active connections to the same port. I know the async webserver does seem to be able to accept a new request while still serving another request, so technically it might be possible. But I guess it might make this plugin quite a bit more complex as you also should handle separate write operations from each connected client.