WiPy/CC3200: usocket.socket.settimeout() not working for socket.getaddrinfo()
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?
ESP32 : socket.connect() blocks even with timeout
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.