← index #3666Issue #8326
Related · high · value 0.615
QUERY · 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?

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