◐ Shell
clean mode source ↗

fix(fastapi): Prevent double wrapping of sync handlers on FastAPI >= 0.137 by jhonny-on · Pull Request #6569 · getsentry/sentry-python

…ts with FastAPI >= 0.137

FastAPI 0.137 changed include_router() to preserve a router tree instead
of flattening routes. This causes get_request_handler() to be called on
every request rather than once at registration. patch_get_request_handler()
mutates dependant.call in-place, accumulating one _sentry_call wrapper per
request. After ~987 requests Python's 1000-frame recursion limit is hit and
the sync endpoint returns 500 permanently.

Fix: add a _sentry_is_patched sentinel to _sentry_call so subsequent calls
to the patched factory skip re-wrapping an already-patched dependant.

Fixes getsentry#6568

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@jhonny-on mentioned this pull request

Jun 15, 2026

@jhonny-on

@jhonny-on jhonny-on marked this pull request as ready for review

June 15, 2026 16:17

sentry[bot]

@alexander-alderman-webb alexander-alderman-webb changed the title fix(fastapi): guard against _sentry_call accumulation on sync endpoints with FastAPI >= 0.137 fix(fastapi): Prevent double wrapping of sync handlers on FastAPI >= 0.137

Jun 15, 2026

alexander-alderman-webb

masonpetrosky added a commit to masonpetrosky/fantasy-foundry that referenced this pull request

Jun 17, 2026
…ler wrapper leak

sentry-sdk <2.63.0 re-wraps a route's dependant.call in _sentry_call on every
request under fastapi>=0.137 (no double-wrap guard, sync handlers only); the
chain grows ~1 frame/request until it exceeds Python's recursion limit, 500ing
every sync server-rendered page (/, /player/<slug>, ...) once the long-running
process has served enough requests. A restart hid it, so it recurred ~daily.

Upstream fix getsentry/sentry-python#6569 ("Prevent double wrapping of sync
handlers on FastAPI >= 0.137"). Reproduced locally: on 2.62.0 a sync SSR route
500s at the ~988th request (matches the prod traceback's "[Previous line
repeated 988 more times]"); on 2.63.0 it survives indefinitely.

Adds a regression guard (sentry-sdk >= 2.63.0 while on fastapi >= 0.137) and
syncs the project-summary backend pytest file count (211 -> 214).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>