#2424 defect new
☂ Allow Twisted programs to behave correctly with respect to changes in the system clock
|Reported by:||rfg007||Owned by:|
|Cc:||spiv, ivank, zooko@…||Branch:|
Description (last modified by glyph)
Twisted currently assumes that the wall clock and system clock times are perfectly synchronized, and provides no facility for compensating when that stops being true.
This is a problem because the mechanism for "when to wake up" for callLater is decided by passing a timeout parameter to the operating system multiplexing API - select() (or similar). This API generally considers "time" to be "the monotonic clock".
This can manifest in a few ways:
- There's no way to schedule a repeated call - using LoopingCall or otherwise - which reliably runs in the face of the system clock being moved backward. If you are trying to schedule a call every 10 milliseconds, and the system clock is moved backward by a day, the timestamp inside the callLater will indicate that it should not run again until 1 day plus 10 milliseconds have passed.
- If you set a 60 minute timeout with callLater, wait 30 minutes, and then put your system to sleep for 120 minutes, when it wakes up it will wait an additional 30 minutes to trigger the call, unless there's some other activity which wakes up the reactor, in which case it will fix itself and get called immediately.
- If NTP introduces a large slew, the frequency of LoopingCall invocations will slow down or speed up accordingly.
To fix this, we will need to:
- introduce 2 new APIs: callAfter and callAt, which use the monotonic and wall clocks respectively
- try to monitor for notifications about "wake from sleep" and "system clock changed" events, on Windows, Mac, Linux, and FreeBSD, to the extent that that's possible.
- expose a new API, callWhenTimeChanged or something like that, to detect deltas between monotonic and wall clocks and allow applications to make specific corrections for them.
A ticket should be filed for each of these pieces of work.
Change History (43)
comment:6 Changed 6 years ago by ivank
- Summary changed from task.LoopingCall: a problem if change the system time to Add reactor option to start with monotonic clock (was: LoopingCall problem)
Changed 6 years ago by ivank
Changed 4 years ago by glyph
comment:39 Changed 13 months ago by glyph
- Summary changed from Add reactor option to start with monotonic clock (was: LoopingCall problem) to Allow Twisted programs to behave correctly with respect to changes in the system clock
comment:40 Changed 13 months ago by glyph
- Description modified (diff)
- Summary changed from Allow Twisted programs to behave correctly with respect to changes in the system clock to ☂ Allow Twisted programs to behave correctly with respect to changes in the system clock