Skip to content

fix:Rollback SQLAlchemy session on asyncio cancellation#103

Open
forsakenMystery wants to merge 1 commit intoSyntaxArc:masterfrom
forsakenMystery:fix/cancellederror-rollback
Open

fix:Rollback SQLAlchemy session on asyncio cancellation#103
forsakenMystery wants to merge 1 commit intoSyntaxArc:masterfrom
forsakenMystery:fix/cancellederror-rollback

Conversation

@forsakenMystery
Copy link

Description

This change ensures async atomic transactions are safely rolled back when an async task is cancelled (e.g., request cancelled/client disconnect, timeouts, TaskGroup cancellation, shutdown).
asyncio.CancelledError is a BaseException since Python 3.8, so it bypasses except Exception and previously skipped the rollback path, risking leaked/open transactions and pinned connections.
We now explicitly catch cancellation/termination exceptions, run a shielded rollback for DB safety, and re-raise to preserve cancellation semantics. This aligns with known cancellation-hardening patterns used in async SQLAlchemy cleanup paths.

Type of change

Bug fix

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has been open for 30 days with no activity.
To keep this pull request open, please: - Add a comment with any updates or progress - Add the not-stale label
This pull request will be automatically closed in 5 days if no activity occurs.

@github-actions github-actions bot added the stale label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant