Skip to content

fix: avoid spurious "exception in shielded future" logs on cancellation#1624

Open
Bathula-Adiseshu wants to merge 1 commit into
temporalio:mainfrom
Bathula-Adiseshu:fix/1600-shielded-future-log
Open

fix: avoid spurious "exception in shielded future" logs on cancellation#1624
Bathula-Adiseshu wants to merge 1 commit into
temporalio:mainfrom
Bathula-Adiseshu:fix/1600-shielded-future-log

Conversation

@Bathula-Adiseshu

Copy link
Copy Markdown

What was changed

Replaced internal asyncio.shield() usage in workflow outbound cancellation loops with a custom _shield_await() helper.

The helper uses asyncio.wait() to preserve the behavior we need:

  • the underlying future is not cancelled when the waiting task is cancelled
  • the future result/exception is still propagated correctly
  • avoids the internal asyncio.shield() exception logging callback that caused spurious ERROR logs

Added regression coverage to verify cancelling workflows with in-flight activities does not emit "exception in shielded future" ERROR logs.

Why?

On Python 3.11+, asyncio.shield() can attach an internal exception logging callback when the outer task is cancelled.

Temporal workflow cancellation handling intentionally catches CancelledError, clears cancellation state, and waits for the operation to finish. In this flow, the original shield callback could remain attached to the future. When the activity later completed with an ActivityError due to cancellation, the workflow handled it correctly, but the leftover callback produced an orphan ERROR log.

This change removes that behavior while keeping the cancellation semantics required by Temporal.

Checklist

  1. Closes [Bug] Single spurious "exception in shielded future" ERROR log per cancelled in-flight activity on Python 3.11+ (residual after #1523) #1600

  2. How was this tested:

  • Added regression test:
    • test_workflow_cancel_no_shielded_future_log
  • Verified with:
    • poe lint
    • pytest tests/worker/test_workflow.py::test_workflow_cancel_no_shielded_future_log
    • pytest tests/worker/test_workflow.py
  1. Any docs updates needed?

No docs updates needed.

@Bathula-Adiseshu Bathula-Adiseshu requested a review from a team as a code owner June 27, 2026 11:38
@CLAassistant

CLAassistant commented Jun 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Single spurious "exception in shielded future" ERROR log per cancelled in-flight activity on Python 3.11+ (residual after #1523)

2 participants