micropython / micropython/micropython-lib

Non-blocking usocket.socket().read() blocks

Open
#381 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

My Sonoff TH with 8266 board and MicroPython 1.11 "locks up" regularly (likely after some network disruption). After sending a ping to the device, I can reconnect to WebREP and interrupt the uasyncio.get_event_loop().run_forever().

I get this traceback every time (roughly daily, sometimes less often).

Welcome to MicroPython!
Password:
WebREPL connected
>>> Ctrl-C
Traceback (most recent call last):
  File "main.py", line 9, in <module>
  File "main.py", line 6, in start
  File "uasyncio/core.py", line 154, in run_forever
  File "uasyncio/core.py", line 109, in run_forever
  File "circ.py", line 102, in mqtt_sub_worker
  File "umqtt/simple.py", line 204, in check_msg
  File "umqtt/robust.py", line 42, in wait_msg
  File "umqtt/robust.py", line 40, in wait_msg
  File "umqtt/simple.py", line 168, in wait_msg
KeyboardInterrupt:
>>> 

https://github.com/micropython/micropython-lib/blob/f20d89c6aad9443a696561ca2a01f7ef0c8fb302/umqtt.simple/umqtt/simple.py#L168

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at umqtt/simple.py line 168, the socket read shown in the traceback, and trace how umqtt.simple.wait_msg handles the reported network disruption. Reproduce the blocking behavior on the MicroPython 1.11 setup if possible; done means a non-blocking socket read no longer leaves the event loop blocked in this failure case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.