← index #4801Issue #8326
Related · high · value 1.138
QUERY · ISSUE

sock.connect(socket.getaddrinfo(ip,port)[0][-1]) takes too long to respond

openby hetvishah08opened 2019-05-21updated 2019-05-24

I'm trying to use usocket library in my application on ESP32 DevkitC and I want to develop a software where if I input a wrong host address it should respond quickly, reset and try again through a webserver based configuration.

sock.connect(socket.getaddrinfo(slave_ip, slave_port)[0][-1])

During testing, I intentionally input the wrong address and it takes around 19 seconds, after which it responds with this error:

[Errno 113] EHOSTUNREACH

I want to reduce this time so that i can perform some other actions.
P.S: sock.setblocking(False) is not an option.

CANDIDATE · ISSUE

ESP32 : socket.connect() blocks even with timeout

closedby AmirHmZzopened 2022-02-19updated 2023-11-20
port-esp32

I'm trying to connect to a TCP socket server. My code works properly when the destination server is listening, but when my server goes down and is not running, socket.connect() blocks about 10 seconds even with socket.settimeout(2).

import socket
async def test() :
    ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0]
    s = socket.socket(ai[0], ai[1], ai[2])
    s.settimeout(2)
    s.connect(ai[-1]) # This blocks for 10 seconds
    ...

Is there any other way to set timeout for socket.connect() ? I've also tried uasyncio.wait_for() to call test() with timeout but that is not working too.

I should mention that I'm using this release which is micropython 1.18 based on IDF 4.2 on a Wemos D1 R32 board which uses ESP32-WROOM-32.

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