← index #7983PR #890
Related · high · value 0.098
QUERY · ISSUE

Socket connect timeout - Feature request

openby Tangerinoopened 2021-11-10updated 2021-11-10

My use case is:

MP is connected to a network where can reach the internet (upstream network) and devices in the LAN (downstream network).
Is known that downstream devices are there and sometimes many, I need to reduce the sock.connect(addr) timeout out so this blocking call does not hang the whole system too much.

So an optional timeout parameter (in msec) would be helpful.

Thank you.

CANDIDATE · PULL REQUEST

settimeout for mqtt socket

mergedby prabhu-yuopened 2024-07-03updated 2024-11-07

Problem statement:
If there are any network issues, mqtt will block on socket non-deterministically.
In such cases, only way to come out of the blocking is to reboot using watch dog timers.
This is costly solution.

Solution:
Alternatively, developer can set the max timeout for the socket.
Upon any issue, mqtt lib will throw exception. Developer can catch it, take
right actions like, restarting the task without rebooting the whole device.

This brings determinism and gives the control to developer to choose right time for her/his use case. This fix works for async applications too.

(I plan to make whole umqtt async compatible.)

4 comments
dpgeorge · 2024-10-18

I plan to make whole umqtt async compatible.

See https://github.com/tve/mqboard/tree/master/mqtt_async

prabhu-yu · 2024-10-20

I plan to make whole umqtt async compatible.

See https://github.com/tve/mqboard/tree/master/mqtt_async

Thank you for the link.
Is it going to be part of the micropython? [https://github.com/micropython/micropython-lib/tree/master/micropython]
If so, it will have higher visibility.

dpgeorge · 2024-10-21

Thank you for the link.
Is it going to be part of the micropython?

Actually, this is a better version: https://github.com/peterhinch/micropython-mqtt

Eventually we would like to add links from this repository to external/third-party libraries like the above, to make them easier to install, and have better visibility.

prabhu-yu · 2024-11-01

I plan to make whole umqtt async compatible.

See https://github.com/tve/mqboard/tree/master/mqtt_async

This will be a lot helpful to all those who use async. Async really shines as it gives better control to developer over threads/processes in terms of scheduling. This in turn solves many locking issues that are common in threads. in anycase, async mqtt blends nicely into all async applications.

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