Skip to content

fix: Prevent long reconnect delays or skipped backoff after a system clock change - #80

Merged
jsonbailey merged 4 commits into
mainfrom
jb/sdk-3308/monotonic-clock
Oct 19, 2026
Merged

jsonbailey merged 4 commits into
mainfrom
jb/sdk-3308/monotonic-clock

Conversation

@jsonbailey

@jsonbailey jsonbailey commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The reconnect delay, the backoff-reset window, and the time-limit error strategy measured elapsed time with the wall clock (time.time()). A clock change during an outage could stretch the reconnect sleep by the size of the change, or skip backoff entirely.

  • Use time.monotonic() for all interval arithmetic in the sync and async clients and in _TimeLimitErrorStrategy. The retry-jitter random seed still uses time.time().
  • Add tests that step the wall clock back one hour on each read and confirm the delay and time limit are unaffected.

Note

Overview
Reconnect timing no longer follows wall-clock jumps. Sync and async SSE clients now use time.monotonic() for reconnect sleep math, disconnect timestamps, and the backoff-reset window instead of time.time(), so NTP or manual clock changes during an outage cannot inflate reconnect delays or incorrectly reset backoff.

Time-limited error retry uses the same clock. _TimeLimitErrorStrategy measures elapsed retry time with time.monotonic() as well.

Tests sleep slightly past time limits on Windows (~15ms clock steps) and add cases that advance time.time() by an hour per read while asserting reconnect delays and backoff reset behavior stay correct.

Reviewed by Cursor Bugbot for commit b52853c. Bugbot is set up for automated code reviews on this repo. Configure here.

@jsonbailey
jsonbailey marked this pull request as ready for review October 19, 2026 14:21
@jsonbailey
jsonbailey requested a review from a team as a code owner October 19, 2026 14:21
@tanderson-ld
tanderson-ld self-requested a review October 19, 2026 14:31
@jsonbailey jsonbailey changed the title fix: Keep reconnect delays correct when the system clock changes fix: Prevent long reconnect delays or skipped backoff after a system clock change Oct 19, 2026
@jsonbailey
jsonbailey merged commit edf5946 into main Oct 19, 2026
19 checks passed
@jsonbailey
jsonbailey deleted the jb/sdk-3308/monotonic-clock branch October 19, 2026 15:08
jsonbailey pushed a commit that referenced this pull request Oct 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.7.4](1.7.3...1.7.4)
(2026-10-19)


### Bug Fixes

* Prevent long reconnect delays or skipped backoff after a system clock
change
([#80](#80))
([edf5946](edf5946))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Release 1.7.4** — bumps the published version from `1.7.3` to
`1.7.4` in `pyproject.toml`, `ld_eventsource/version.py`, and
`.release-please-manifest.json`, and documents the release in
`CHANGELOG.md`.
> 
> The changelog entry calls out the included bug fix
([#80](#80)):
reconnect backoff no longer misbehaves when the system clock jumps
(avoiding excessive delays or skipped backoff).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f7f7aa2. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants