#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 )
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
LoopingCallor 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
callLaterwill 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:
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,
callWhenTimeChangedor 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 7 years ago by
|Summary:||task.LoopingCall: a problem if change the system time → Add reactor option to start with monotonic clock (was: LoopingCall problem)|
comment:39 Changed 22 months ago by
|Summary:||Add reactor option to start with monotonic clock (was: LoopingCall problem) → Allow Twisted programs to behave correctly with respect to changes in the system clock|
comment:40 Changed 22 months ago by
|Summary:||Allow Twisted programs to behave correctly with respect to changes in the system clock → ☂ Allow Twisted programs to behave correctly with respect to changes in the system clock|