Hi,
I've written a (HTTP 1.0) web server which will have various features, for the esp8266 running in Micropython (1.8.4 actually the latest built)
This is all running perfectly most of the time, but there is a case where it isn't.
If a web browser opens two sockets at once, perhaps a second one before the first has even been accepted, then the last socket to be opened, accept() never accepts it.
Let's give an example. I have a html page, css file and .js file. The first two load fine, the third one does not. It either hangs forever the connection, or closes the connection without a response.
I'll attach a packet capture (pcap) file and link the source code.
Source code is here:
https://github.com/MarkR42/esp-webui/bl ... ver.py#L19
it is in a loop calling accept() on the listen socket.
Any ideas what's happening? Has anyone seen it before?
socket accept() does not (always) accept
socket accept() does not (always) accept
- Attachments
-
- webserver_fails.zip
- (4.07 KiB) Downloaded 259 times
Re: socket accept() does not (always) accept
You might want to try bumping up the backlog for queued connections. I noticed you currently have
and with that at most one accept connection can be queued at a time. So if you have three connections, one being handled, one in queue, and another incoming the third will not be handled. I haven't played around with it much, but I would think the third connection should be rejected outright rather than hanging around, so it doesn't match exactly with what you're seeing, but maybe it's some quirk.
It's probably worth trying it with a higher backlog to see if it resolves your problem.
Code: Select all
sock.listen(1)
It's probably worth trying it with a higher backlog to see if it resolves your problem.
Last edited by chrisgp on Wed Oct 05, 2016 8:33 pm, edited 3 times in total.
Re: socket accept() does not (always) accept
That sounded really plausible, however, I've increased it to 5 and it made no difference at all.