me-no-dev / ESPAsyncTCP

Async TCP Library for ESP8266
GNU Lesser General Public License v3.0
758 stars 394 forks source link

[Solved] More than one AsyncServer at the same time? #164

Closed Miq1 closed 3 years ago

Miq1 commented 3 years ago

I have an application here that needs to serve three separate TCP ports - 23 (Telnet), 80 (HTTP) and 502 (Modbus). I have set up three AsyncServer instances in parallel. While this seemed to work at the beginning, I am experiencing crashes now, if I get a Modbus request while a Telnet output is done.

Is it valid at all to run more than one AsyncServer at the same time?

Miq1 commented 3 years ago

I can narrow it down now to a situation, where the Modbus AsyncServer is trying to send a log line to the Telnet AsyncServer. So from within a onData() Modbus callback I am trying to have the Telnet server do a client.write().

Could this provoke a race condition between the two AsyncServers that is 'solved' by the WDT?

Miq1 commented 3 years ago

The reason was:

The solution was to write in the callback function into a buffer and have the Telnet server work on the buffer later, after the callback had returned.