Skip to content

fix(auth): prevent OverflowError in auto-refresh token retry (#1397) - #1400

Merged
o-santi merged 1 commit into
supabase:mainfrom
SM1LE-X:fix/auth-retry-overflow
Mar 12, 2026
Merged

o-santi merged 1 commit into
supabase:mainfrom
SM1LE-X:fix/auth-retry-overflow

Conversation

@SM1LE-X

@SM1LE-X SM1LE-X commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Issue

Fixes #1397

What is the current behavior?

When a token refresh fails with an AuthRetryableError, the _start_auto_refresh_token method calculates an exponentially massive retry interval RETRY_INTERVAL ** (self._network_retries * 100). On the very first retry, this evaluates to 2^100 milliseconds, which exceeds the platform's time_t limit and triggers an OverflowError that crashes the thread.

What is the new behavior?

This PR updates the backoff calculation to match the auth-js reference implementation: 200 * (2 ** (self._network_retries - 1)).

This provides a sane exponential backoff (200ms → 400ms → 800ms) instead of overflowing.

Changes made:

  • Updated the backoff formula in both supabase_auth/_sync/gotrue_client.py and supabase_auth/_async/gotrue_client.py.
  • Removed the RETRY_INTERVAL import from both files as it is no longer used.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.

@coderabbitai

coderabbitai Bot commented Feb 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 59e3384 and 20d3a9e.

📒 Files selected for processing (2)
  • src/auth/src/supabase_auth/_async/gotrue_client.py
  • src/auth/src/supabase_auth/_sync/gotrue_client.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Optimized authentication retry logic with improved backoff timing for more consistent and responsive error recovery during network connectivity issues affecting token refresh operations.

Walkthrough

This pull request fixes a critical OverflowError in the retry backoff calculation for token auto-refresh in the Supabase auth client. The exponential backoff formula RETRY_INTERVAL ** (network_retries * 100) is replaced with a fixed progressive backoff formula 200 * 2^(network_retries - 1) in both the async and sync implementations of gotrue_client.py. The RETRY_INTERVAL constant is removed from imports. This changes retry delays from astronomically large values (2^100 milliseconds on first retry) to reasonable, capped intervals (200ms, 400ms, 800ms, etc.).

Assessment against linked issues

Objective Addressed Explanation
Fix OverflowError in retry backoff caused by exponential calculation of RETRY_INTERVAL ** (network_retries * 100) [#1397] ✅

Comment @coderabbitai help to get the list of available commands and usage tips.

@o-santi
o-santi merged commit 08bdf38 into supabase:main Mar 12, 2026
22 of 40 checks passed
moshemorad added a commit to HolmesGPT/holmesgpt that referenced this pull request May 25, 2026
…n auto-refresh (#2029)

## Summary

Bumps the pinned `supabase` dependency from `2.28.0` → `2.28.1` to pull
in
[supabase/supabase-py#1400](supabase/supabase-py#1400),
which fixes an `OverflowError: timestamp out of range for platform
time_t` raised from `supabase-auth`'s token auto-refresh background
thread.

Linear: [ROB-3871](https://linear.app/robusta/issue/ROB-3871)
Sentry: [HOLMES-1S](https://robusta-eu.sentry.io/issues/89219836/) — 264
occurrences across 144 clusters, releases 0.20.0 → 0.22.0.

## Root cause

`supabase-auth==2.28.0` schedules the retry path of its auto-refresh
`Timer` with a formula that overflows the OS `time_t` on the *first*
retry:

```python
# supabase_auth/_sync/gotrue_client.py
self._start_auto_refresh_token(
    RETRY_INTERVAL ** (self._network_retries * 100)
)
```

With `RETRY_INTERVAL = 2` and `_network_retries = 2`:

- `2 ** 200` ≈ **1.61 × 10⁶⁰** milliseconds
- `Timer.__init__` stores the value as `_milliseconds` and `start()`
divides by `1000` → **1.6069380442589903 × 10⁵⁷ seconds**
- That flows: `threading.Timer.run` → `Event.wait` → `Condition.wait` →
`lock.acquire(True, timeout)` → C-level `time_t` overflow.

The captured Sentry value `1.6069380442589903e+57` matches `2 ** 200 /
1000` exactly.

### Why Holmes hits it

The `toolset-refresh` daemon thread (`server.py:238`) uses
`self.client.auth.set_session(...)` (`holmes/core/supabase_dal.py:269`),
which arms `supabase-auth`'s auto-refresh `Timer`. When the periodic
refresh HTTP call fails with `AuthRetryableError` — visible in
breadcrumbs as `JWT token expired/invalid, signing in to Supabase again`
— the buggy retry path arms the Timer with the absurd interval and the
daemon thread dies. Holmes silently recovers via the next periodic
`sign_in_with_password`, so users don't see breakage, but Sentry keeps
capturing unhandled threading exceptions.

## Upstream fix

[PR #1400 / commit
`08bdf38`](supabase/supabase-py#1400), released
in `supabase` / `supabase-auth` **2.28.1** on 2026-03-13:

```diff
-                        (RETRY_INTERVAL ** (self._network_retries * 100)),
+                        (200 * (2 ** (self._network_retries - 1))),
```

Proper exponential backoff, capped at ~102 s on the 10th retry.

## Changes in this PR

- `pyproject.toml`: `supabase = "2.28.0"` → `supabase = "2.28.1"` (kept
the exact-pin style)
- `poetry.lock`: regenerated with the matching `poetry==2.3.3`. Only the
supabase family (`supabase`, `supabase-auth`, `supabase-functions`,
`postgrest`, `realtime`, `storage3`) is bumped to 2.28.1 in lockstep. No
other packages touched.

## Verification

```bash
git diff poetry.lock | grep -E "^[+-]version = " | sort -u
# +version = "2.28.1"
# -version = "2.28.0"
```

No Holmes source changes are required.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
  * Updated Supabase dependency to version 2.28.1

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/HolmesGPT/holmesgpt/pull/2029)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Mohse Morad <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

OverflowError in gotrue auto-refresh retry: RETRY_INTERVAL ** (network_retries * 100) overflows time_t

2 participants