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

utimeq overflows after reaching 0x3fffffff, while ticks_ms values will grow larger #232

Closed martijnthe closed 5 years ago

martijnthe commented 5 years ago

utimeq is mostly used in conjunction with ticks_ms() in uasyncio, where "timestamps" generated by ticks_ms() are passed into the queue to sort the elements in the queue.

What the problem is depends a bit on what you deem "correct". The values returned from ticks_ms() can grow larger than utimeq's fields to hold the time values. peektime() can only return values up to 0x3fffffff ((1 << 30) - 1).

If one attempts to use uasyncio on a Pycom board, sooner or later (after 12.42 days when the overflow happens) mayhem will happen because of this wrap-around...

I guess one fix would be to make ticks_ms() wrap at 0x3fffffff as well and fix ticks_diff() to return serial distance (taking wrap-arounds into account) -- see #231. Another could be to change utimeq to be able to handle larger time values.

Related issues: #231, #112.

cc @robert-hh @iwahdan88

martijnthe commented 5 years ago

Part of the problem: https://github.com/micropython/micropython/issues/4336

robert-hh commented 5 years ago

See alsomy comment here: https://github.com/pycom/pycom-micropython-sigfox/issues/231

husigeza commented 5 years ago

Hello! PR235 will fix this problem, thanks @robert-hh for the fix.