← index #4801Issue #3666
Related · high · value 0.112
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

WiPy/CC3200: usocket.socket.settimeout() not working for socket.getaddrinfo()

openby dmartauzopened 2018-03-09updated 2018-03-16

In issue https://github.com/micropython/micropython/issues/2402 a solution was proposed to make socket.settimeout() working for socket.connect(). It seems to work well.

However it does not work for socket.getaddrinfo() as there seems to be fixed timeout of 19s.

import socket
import ssl
import time

def test():
	start = time.time()
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
	s = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/flash/cert/ca.pem')
	s.settimeout(3)
	try:
		print(socket.getaddrinfo("www.google.com", 443)[0][-1])
	except Exception as e:
		print(e)
	finish = time.time()
	print(finish - start)
	s.close()

EDIT: Looking at the code once again it is obvious that calling settimeout() method of socket instance cannot affect timeout of socket.getaddrinfo(). Anyway is there any way how to modify timeout of this method?

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