New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http server runs out of sockets #809
Comments
Well, socketserver.c gets called from Could it be that something about the |
Thanks. |
the debug log has messages about every socket open/close, should be easy to trace what happens there |
@tve - do you mean the console log in the IDE? I was doing some web socket code that involved quite a few sends to the ESP8266 from the ide:
This output doesn't look that helpful.
the create server is failing on socket create... |
I meant the uart1 output. I will look into this issue, but I'm just slammed. |
@tve Is there a way to connect the uart1 to the web ide console as I'm using a nodemcu board? |
Notes for myself ! /*JSON{ /*JSON{ |
mhh, net.kill() causes an exception:
On the esp8266 a reset() does not close server sockets cleanly. A dumpSocketInfo shows that a server socket remains in a disconnecting state. |
Haha, from the code:
Looks like we don't get a disconnected callback... Probably my bad for not double-checking and fixing this. |
Problem still exists in 1.85 |
Steps to reproduce? |
Nothing fancy, just working on a very simple server will trigger the problem after a couple of uploads.
|
This version shows the debug output in the web ide:
I think the issue is here: Espruino/libs/network/esp8266/jswrap_esp8266_network.c Lines 1626 to 1640 in e740e65
which calls:
and since However, I would have thought the slots should be in the |
Ahh - worked out how to reproduce.... It's when you get an inbound connection, while the script is being up loaded. So this naturally when you are using web sockets -as there is a regular heartbeat. So start the ide upload and refresh the browser.... after a few iterations, the
|
IIRC that's because the telnet console is also one of the sockets, so you don't want to blow that away... |
@davidmoshal I cannot reproduce your problem. I'm running curl pulling the hello world page in a loop running as fast as it will go (several requests per second) and it's already been running for a few minutes without any issue. |
@wilberforce are you saying that if you upload code while a socket is open then the socket does not get closed? That's possible. |
@tve are you uploading code at the same time? @wilberforce 's problem seemed exactly the same as mine, so I ran his code, and I get the same error he got - socket count increases until they are dropped:
Note: in my original case I noticed that even without uploading code, the browser seemed to still be waiting after |
@tve I have been doing the tests, uploading with serial. If you upload over a wifi connection it does not seem to occur... |
@tve I was able to reproduce it easily - note: I had to upload the code and refresh the browser about 10 times. David |
This is a simple way howto hammer the ESPRUINO webserver using curl How to quickly stress test a web server
Next level is to use ab Apache HTTP server benchmarking tool using this allows you to quickly reproduce out of sockets and prints some stats
|
@tve is the espressif SDK the root cause ? |
Another easy way to reproduce this issue is to use the Ping Module and spam out ping requests, you soon slam into the error. |
running a sensor, that sends every 5min data to thingspeak.com ( chart )
Is there a context ? |
new gap because sensor moved to a different location - restarted at 15:54 GMT+0200 |
Hi, can some one please explain this output line marke with <-- ?
this is the used command to stress the sockets:
|
The problem starts way before the highlighted line. E:M 656 is printed by malloc and means that it failed to allocate 656 bytes, which must be a TCP buffer. By the looks of it the alloc was called by the SDK, e.g. lwip. The line you highlighted is when the espruino networking code gets the error. |
Hello, |
no - not as far as I know |
We have very periodic problem related to "ERROR: Unable to create socket". |
Hi @msol2004
@tve and @wilberforce would be nice if you can add your findings and suggestions |
Sorry, I can really add much. I've found the esp8266 do be a bit limiting when I try to do anything, so I'm focusing efforts on the esp32 port. There are much more resources available and these type of issues are far less likely to occur. @jumjum123 and I have been working on the esp32 port, there is a esp32 branch and and gitter.im room. |
I am in dead end with "setup a the toolchain". I am focused in Eclipse dev.tools and, unfortunately, I still cannot find the right manual "how to compile Espruino project". Any guidance will be very appreciated! |
check README_Building.md and let me know if you need more informations |
Thank you for your attention! Before your answer, I have found recommendations for "UNOFFICIAL DEVELOPMENT KIT FOR ESPRESSIF ESP8266" and followed them. Very likely, I have installed all things properly, because two sample projects (hello_world and lwip_open_demo_app) have been downloaded into ESP-12F and functioned as expected. Now I am trying to find proper way according to instructions in README_Building.md and README_BuildProcess.md files. I met several questions after the reading README_Building.md under the line "for esp8266": Anyway, I have uncommented the line ESP8266_BOARD=1 and added Log file of my first attempt to build firmware:
Build report:
Could you guide me onto the next step? |
please also check Dockerfile-esp8266 My Env setting:
clone and install flash tool esptool
clone Espruino
check README_flash.txt to flash your new binaries Please let me know if you need more support |
Thank you, it works! |
@msol2004 any news on this? |
The ESP8266 supports only 15 sockets, that's a hardware limitation, and to make it worse the current build of Espruino supports only 10 sockets. I can't see any indication of any other error in the messages in this thread, it looks like you're simply hitting that limit to 10 sockets. Just be clarify, maybe I didn't understand the error report correctly: As far as I understand the sockets get closed eventually, and new connections are possible again ('some gaps in the graphs'). Is this correct? The only thing I don't understand: How could @tve possibly have curl running for minutes without getting any error - was the web server really running on the ESP8266? |
Yes, absolutely! They should get closed pretty quickly.
Because sockets get closed after being used. If they're not getting closed you're doing something wrong, and with 50 sockets you'll probably just run out of RAM before anything else. |
Just checked curl: curl does actively close the connection on the client side, therefore the server can re-use the socket without any wait time, and this is most likely why it worked fine. But if the client doesn't actively close the session the server has to do close the session. This can take a while (4 minutes typically in TIMEWAIT state). |
Espruino doesn't support socket re-use, so I believe it closes the socket itself once it's served up the page. What exact problems are you having with Espruino on ESP8266, and with what code? |
Sorry, I used the wrong terminology. It's re-using one of the 10 available structures for sockets (as defined in MAX_SOCKETS) to create a new socket, not the socket itself. |
Me too :) I think what happened was there was historically a bug where Espruino was 'leaking' open sockets in some cases, and then a bug in the ESP8266 SDK where it did the same when low on memory, but it sounds a lot like this has now been fixed in both cases. I'll just close this now I think and will see if anyone reopens with with a legitimate report of leaking sockets, and not an 'Unable to create socket' that's just caused by trying to open too many sockets. |
Reported by Wilberforce:
When testing and debugging, after a while to http server code fails to start with an out of sockets error.
This happens after a number of uploads from the web ide.
I believe it is due to the old http server sessions not shutting down properly.
I have my board set up so it auto joins my local wifi.
At the moment I just hit the reset button on the board, and re upload, however it would be handy to shutdown the connections cleanly. Can this be down with an E.event on after a .reset?
Wifi.disconnect and wifi.connect() does do the job, however it would be great if an event could trigger.
The text was updated successfully, but these errors were encountered: