Repository navigation
Conversation
OEPStream closed its session in __del__. The response always sits in a reference cycle (Django's request_finished reaches an asgiref Local whose swallowed exception keeps the closing frame alive, and DRF's view and request point at each other), so __del__ ran only at the next full garbage collection. A client that stopped reading a rows download left the connection, its transaction, its snapshot and a lock on the table idle in transaction until then. close() is what the WSGI server calls on completion and on abort alike, so the session is closed there. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A table download through
GET /api/v0/tables/<t>/rows/streams from a server-side cursor on a connection opened for that request. When the client stopped reading, the connection was only given back when the garbage collector next ran a full collection.Why
__del__never ran promptly:response.close()sendsrequest_finished→close_caches→hasattr()on an asgirefLocal, which raises and swallows anAttributeErrorinside acontextmanager; its traceback keeps the frame chain alive up toclose(), whoseselfis the response. DRF adds a second cycle (view ↔ request). Same on production's versions (Django 5.2.17, asgiref 3.8.1, DRF 3.17.2).Until then the request held its pool slot, its transaction, its snapshot and a lock on the table,
idle in transactiononFETCH FORWARD 1. On production on 2026-10-21, two such connections were still open 72 minutes after their downloads had been aborted, and aDROP TABLEon such a table waits for them.Evidence
api/tests/test_regression/test_aborted_row_stream.py, one case per form (JSON, CSV, datapackage), withgcdisabled:FAILED (failures=3), eachAssertionError: 0 != 1(the session is still registered)After:
Ran 3 tests … OKmanage.py test api:Ran 504 tests … OKMerge Danger
Door: two-way
Revert the one method.
Blast Radius: small
OEPStreamserves the REST rows download (all three forms), the advanced API's streamed results andadvanced/cursor/fetch_*(no session there, soclose()only calls Django's). A complete stream already closes its session after the last row; the second close is a no-op, as it was in__del__. An explicit advanced API session that is passed in is closed at the same point it was before, only no longer late — a late close in__del__could close a session the client had meanwhile reused under the same id.🤖 Generated with Claude Code