Behaviour of blocking sockets on WiFi

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Behaviour of blocking sockets on WiFi

Post by pythoncoder » Tue Sep 20, 2016 6:49 am

I've posted this here because of its possible relevance to developers of micropython-lib.

I've been testing blocking sockets on the ESP8266. If the WiFi fails completely the socket (correctly) throws an OSError which can be trapped. However I've experienced rare conditions where the WiFi link is degraded by virtue of distance and/or RF interference where the socket read and write methods can block for long periods - possibly in some circumstances indefinitely. Usually it clears in a few seconds or tens of seconds but I encountered one which only ended when I hit <ctrl>C to discover the cause (socket.write).

Clearly this can't be trapped and will cause an application hang.

Two questions:
  • Is this expected behaviour? I suspect it's inevitable.
  • If so, should blocking sockets be used? A socket timeout is the obvious (and tested) fix.
This condition is rare and hard to replicate reliably.
Peter Hinch
Index to my micropython libraries.

Post Reply