← index #5624Issue #4827
Related · high · value 1.365
QUERY · ISSUE

ESP32: Socket.listen(backlog) leads to OSError: 112

openby mrwhy-origopened 2020-02-08updated 2020-02-11
port-esp32

Currently I'm trying to listen to a socket. My setup is utilizing uasyncio.

But the same error is happening with plain use of sockets as well.

I'm building the master branch with EspIDF 3.3.1

import usocket as _socket
ai = _socket.getaddrinfo("0.0.0.0", 80, 0, _socket.SOCK_STREAM)
ai = ai[0]
s = _socket.socket(ai[0], ai[1], ai[2])
s.setblocking(False)
s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, 1)
s.bind(ai[-1])
s.listen(10)

Edit:
Just finished tests with ESP IDF 4 --> Same problem.

CANDIDATE · ISSUE

OSError: [Errno 113] EHOSTUNREACH while listen for connection

openby nedoskivopened 2019-06-01updated 2023-06-12
port-esp32

Hello,
I was using so far older micropython (1.10 official ) release, but I was testing some stuff and switched to one of the latest:

MicroPython v1.10-380-g6cf4e9675 on 2019-05-23; ESP32 module with ESP32

problem is that I got a simple web server using usocket to listen for connections:

my code is large i just gonna show how I use socket:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(3)
conn, addr = s.accept()

with older version of micropython (1.10 official) I never got a problem, but with this one from time to time i got:
OSError: [Errno 113] EHOSTUNREACH
failing on line with:
conn, addr = s.accept()
google it and it may be dns related, but there is no dns involved when you listen for connections.

P.S.
It happen at random, I use ajax to reload browser page every 3 seconds, sometime it happen on first minute, some time 30 min need to pass. Good part is I have modified my code and place it in try: except: statement with 1 second time out on failing, so it works now.
P.S.1
After some testing, another problem that happen from time to time appear. When tcp connection is established (listening mode) sometimes it receive zero data. Here is part of the code I use:


		print('[ WEB ] Incoming connection from: %s' % str(addr))
		poller = uselect.poll()
		poller.register(conn, uselect.POLLIN)
		res = poller.poll(10000)  # time in milliseconds
		if not res:
			conn.close()
			print('[ WEB ] INITIAL CONN TIMEOUT')
			poller.unregister(conn)
			continue
		print ("[ WEB ] INITIAL CONN RECV")
		poller.unregister(conn)
		request = conn.recv(512)

from time to time conn.recv receives 0 bytes. None of that happen on older version. I'm already modified my code to handle this, but for sure that is not the way.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied