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
marked this pull request as ready for review
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
masonpetrosky added a commit to masonpetrosky/fantasy-foundry that referenced this pull request
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters