adafruit / Adafruit_CircuitPython_NTP

Network Time Protocol (NTP) Helper for CircuitPython
MIT License
9 stars 18 forks source link

OverflowError #35

Open tedder opened 1 month ago

tedder commented 1 month ago

After less than 24hrs, datetime() seems to fail right now. I haven't debugged what's causing it, though it seems to be from self._monotonic_start.

  File "adafruit_ntp.py", line 97, in datetime
OverflowError: overflow converting long int to machine word

Here's a link to the current version of the file: https://github.com/adafruit/Adafruit_CircuitPython_NTP/blob/4a5775a3d972ed9686bfde3b588c399f8e270c4d/adafruit_ntp.py#L97

tannewt commented 1 month ago

What board are you running this on? A few small ones don't have long int support (where ints are allocated to the heap.)

tedder commented 1 month ago

It's the qtpy esp32 s2 running 9.x:

Adafruit CircuitPython 9.0.4 on 2024-04-16; Adafruit QT Py ESP32S2 with ESP32S2
Board ID:adafruit_qtpy_esp32s2
UID:[..]
tedder commented 1 month ago

Not sure if it's helpful, but:

>>> g=2147483640
>>> print(g)
2147483640
>>> g+=90000
>>> print(g)
2147573640
>>> print(type(g))
<class 'int'>

Also confused why it works some of the time. seconds is the only value that changes in that _monotonic_start equation, I'd think.

tannewt commented 1 month ago

Try printing seconds. I wonder if the struct unpack is causing the issue.

tedder commented 1 month ago

since the failure is intermittent, I'm not sure if/when I'll be able to catch it. For now, here's the type and value:

<class 'int'> 3930136863
tedder commented 1 month ago

ooo, I got one.

<class 'int'> 3930141298
<class 'int'> 0
OverflowError: overflow converting long int to machine word

Note that's two calls, the second one failed.

tedder commented 1 month ago

sending two PRs.

37 prevents the socket call from happening every few seconds, which reduces the chances of failure.

38 does a sanity check to ensure the value is valid. it means a new error needs to be caught.

It's possible there's a better fix to the root cause, but these turn it into a known problem, at least.