pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
199 stars 167 forks source link

usocket.connect() to down server ignores timeout and no exception thrown #34

Open mfallavol opened 7 years ago

mfallavol commented 7 years ago

WiPy 2.0 v1.8.6-650-g9bacbbd4 on 2017-06-09'

When I attempt to make a socket connection to a machine that is down the timeout value is completely ignored and connect() doesn't throw an exception.

Example code:

import time import socket def test1(): start = time.time() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) s.settimeout(3) s.connect(('192.168.1.120', 15000)) finish = time.time() print(finish - start) s.close()

This takes 18-19 seconds and throws no exception.

campbellsinclair commented 5 years ago

I can confirm that connect() doesn't throw a timeout exception. For me it throws "OSError: -1" after an unspecified amount of time, whether I set a timeout or not.

WiPy 3.0 release 1.18.1.r1

Motivation: Minimise the time network hardware is being used because it consumes a large amount of energy. This is particularly wasteful when using the LTE modem of a GPy, which consumes ~200mA.