Repository navigation
stop forced coroutine unloading from emitting durable work - #164
Merged
Tomer Rosenthal (torosent) merged 1 commit intoSep 29, 2026
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Tomer Rosenthal (torosent)
marked this pull request as ready for review
September 29, 2026 15:21
Copilot started reviewing on behalf of
Tomer Rosenthal (torosent)
September 29, 2026 15:21
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The teardown guards are consistently applied and backed by comprehensive unit and DTS integration coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents forced coroutine unloading from emitting durable work or logs while preserving normal deferred cleanup behavior.
Changes:
- Guards durable APIs during forced unwind with
ErrTaskBlocked. - Prevents late long-timer chunks and suppresses unwind logging.
- Adds unit/E2E coverage and cleanup guidance.
| File | Description |
|---|---|
README.md |
Documents deferred cleanup patterns. |
CHANGELOG.md |
Records teardown fixes. |
task/context.go |
Suppresses unwind logging. |
task/eventchannel.go |
Guards event-channel operations. |
task/orchestrator.go |
Adds unwind guards across durable APIs. |
task/scheduler.go |
Tracks forced stack unwinding. |
task/select.go |
Guards selection during teardown. |
task/select_test.go |
Supports executor options in tests. |
task/task.go |
Guards task creation and awaiting. |
task/teardown_test.go |
Tests teardown behavior comprehensively. |
task/waitgroup.go |
Guards waits and documents cancellation. |
tests/durabletaskscheduler/dts_teardown_test.go |
Verifies behavior against DTS. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Sep 29, 2026
halspang
approved these changes
Sep 29, 2026
Tomer Rosenthal (torosent)
deleted the
torosent-coroutine-teardown-safety
branch
September 29, 2026 21:42
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.
The problem
The SDK stops waiting coroutines between execution turns and when an orchestration ends. Go runs their
deferfunctions during that shutdown—even when the workflow has not finished normally.For example, a child coroutine waiting for an event could have deferred a cleanup activity. When the parent finished, shutting down the child could schedule that activity after the orchestration was already marked complete. Defers could also overwrite custom status or consume events that should be kept for the next execution.
We reproduced the extra activity schedule on both the emulator and live DTS. Both accepted and stored it after completion. We did not observe activity dispatch during the test window; that does not prove it can never happen.
The fix
ErrTaskBlockedsignal, before they change workflow state.ctx.Logger()output during shutdown.What this means for cleanup
Normal-return defers still work: they can schedule and await durable work, including across replay.
During forced shutdown, a durable call stops the rest of that deferred function. Other defers, such as metrics or
span.End, still run on each unload.Required cleanup must finish before the parent returns. Cancel the child's work, keep its cleanup in an uncanceled scope, and wait for the child to finish. The README includes this pattern.