fix: Preserve original exception cause in timeout context managers (closes #16299)#22262
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46b5e4027d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| except CancelledError: | ||
| raise timeout_exc_type(f"Scope timed out after {seconds} second(s).") | ||
| except CancelledError as e: | ||
| raise timeout_exc_type(f"Scope timed out after {seconds} second(s).") from e |
There was a problem hiding this comment.
Preserve the cause for sync timeouts too
This change only chains the CancelledError in timeout_async, but the sync timeout context manager below still raises an unchained TimeoutError. Sync tasks use timeout directly (src/prefect/task_engine.py:1008) and sync flows select it when self.flow.isasync is false (src/prefect/flow_engine.py:1274), so those timeout failures continue to lose the underlying cancellation cause this fix is meant to preserve. Please mirror the except CancelledError as e / raise ... from e change in the sync path as well.
Useful? React with 👍 / 👎.
Merging this PR will not alter performance
Comparing Footnotes
|
|
hi @botbikamordehai2-sketch thanks for opening a PR this seems incomplete and afaict over-claims the fix. it only chains the async also, #16299 appears to be about DB latency/locking/server starvation more than timeout traceback formatting. this may improve traceback readability, but I don’t think it resolves the linked issue. I’d suggest adding sync coverage + tests asserting |
|
This pull request is stale because it has been open 14 days with no activity. To keep this pull request open remove stale label or comment. |
What
When a timeout occurs in the
timeout_asyncortimeoutcontext managers, the originalCancelledErroris caught and re-raised as a genericTimeoutError, losing the underlying cause (e.g., an asyncpg database timeout). This makes debugging difficult, as seen in issue #16299 where database communication timeouts are masked.Fix
Use
raise ... from eto chain the originalCancelledErroras the cause of the newtimeout_exc_typeexception. This preserves the full traceback and allows users to see the original error that triggered the timeout.Closes #16299