socket accept() does not (always) accept

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

socket accept() does not (always) accept

Post by markxr » Wed Oct 05, 2016 12:56 pm

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?
Attachments
webserver_fails.zip
(4.07 KiB) Downloaded 87 times

chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Re: socket accept() does not (always) accept

Post by chrisgp » Wed Oct 05, 2016 3:21 pm

You might want to try bumping up the backlog for queued connections. I noticed you currently have

Code: Select all

sock.listen(1)
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.
Last edited by chrisgp on Wed Oct 05, 2016 8:33 pm, edited 3 times in total.

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: socket accept() does not (always) accept

Post by markxr » Wed Oct 05, 2016 8:00 pm

That sounded really plausible, however, I've increased it to 5 and it made no difference at all.

Post Reply