Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Inq720
#83534 Summary

About two years ago I wrote a generalized HTTP server for the ESP8266 (specifically the WeMos D1 Mini). At that time it was working fine. It would run for days/weeks processing requests with hundreds of browser banging on it. No memory leaks, or squeaks. Fast forward to today – I loaded up my old project in an Arduino environment with the latest Arduino IDE 1.8.9 and the ESP8266 Community version 2.5.2. Refreshing a browser pointed to a hosted web page a couple of times exhausts the 5 connections permitted on the ESP8266 and then it basically stops processing requests.

Working backwards through the old libraries 2.5.1, 2.5.0, 2.4.2… etc, I finally loaded up 2.3.0 and it works as I recall. The issue seems to be the ESP8266 espconn_disconnect() method is no longer cleaning up the connection and firing my espconn_regist_disconcb disconnect callback event.

I am assuming I am missing some new procedure. I have done many Google searches on this site as well as the Internet at large for both of the methods above as well as changes in the libraries between 2.3.0 and 2.4.0. I’m not having any luck.

Any help would be appreciated. Thanks.


More Details

Here are the espconn steps I’m doing in code that work for the old 2.3.0 library.

1. I have a C++ object representing this one client browser connection.

2. When a new browser connection is requested, the espconn_regist_connectcb callback is fired and it is forwarded to one of these objects. In it I…
a. Store a reference to the supplied espconn*
b. Set the espconn->reserve to this object
c. Set the espconn_regist_recvcb, espconn_regist_sentcb, and espconn_regist_disconcb callbacks
d. Set the espconn_set_opt

3. The espconn_regist_recvcb eventually gets called and I read the incoming browser request and set the C++ object to process the request in the next Arduino loop cycle. I do not do the actual processing in the callback.

4. The next loop reads and outputs the requested SPIFF file. Depending on size of the file, this is handled over multiple loop cycles so that minimal time is used.

5. The file is closed and espconn_disconnect method is called.

6. In the 2.3.0 library, the espconn_regist_disconcb event is called consistently 1 ms later. In any of the more recent libraries (2.4.0 – 2.5.2) I never receive the [b]espconn_regist_disconcb[/b] callback.
User avatar
By Inq720
#83535 More Research

Found this excerpt in Ivan Grokhotkov's 2.4.0 documentation: https://buildmedia.readthedocs.org/media/pdf/arduino-esp8266/2.4.0/arduino-esp8266.pdf

14.4.2 Libraries
• Better connection handling in ESP8266WebServer. The server now sends Content-Length and Connection:
close headers, then waits for the client to disconnect. By not closing the connection actively, server avoids
TIME_WAIT TCP state, and TCP stack is able to release the memory immediately, without waiting for 2xMSL
period. If the client doesn’t disconnect in 2000ms, the server closes the connection actively.

This sounds like its related, but I'm not getting the disconnect in 2000ms and I'm not sure what the work around is.