esp8266: socket accept() does not always accept
If there is a queue of sockets to accept, accept() does not always clear it, some sockets seem to get "lost", they are still open but accept() will not accept them, it just blocks.
Steps to reproduce
I'm attaching two programs - main.py and client.py. Run client.py on a connected system, under normal python3. Run main.py on an esp8266. Supply the address of the esp8266 as a command line parameter.
Expected results
Despite the sleep(0.25), the sockets should queued and be accepted eventually.
Output should be, for example:
Socks connected: 4
b'Accept 0'
b'Accept 1'
b'Accept 2'
b'Accept 3'
And running the program >1 time should also succeed.
Actual results:
Socks connected: 4
b'Accept 0'
b'Accept 1'
b''
b''
esp8266: socket blocking settings are inherited by accept() when they probably shouldn't be
Test code:
import time, socket
s = socket.socket()
s.bind(socket.getaddrinfo("0.0.0.0", 8000)[0][-1])
s.setblocking(False)
s.listen(1)
while True:
try:
s2, _ = s.accept()
break
except OSError as er:
print(repr(er))
time.sleep(1)
print('connection')
s2.recv(10)
On CPy and uPy unix, running the above code and connecting to the socket will block indefinitely at the last line, because the accepted socket s2 defaults to blocking mode.
On esp8266 the accepted socket s2 inherits the non-blocking behaviour from s.