fix(runtime-sdk): ensure finalize_request is alive inside wait_until call - #250
Draft
ryanking13 wants to merge 2 commits into
Draft
fix(runtime-sdk): ensure finalize_request is alive inside wait_until call#250ryanking13 wants to merge 2 commits into
ryanking13 wants to merge 2 commits into
Conversation
|
|
||
| wait_until(run_in_background(finalize_request())) | ||
| finalizer_task = run_in_background(finalize_request()) | ||
| task_proxy = create_proxy(finalizer_task) |
There was a problem hiding this comment.
create_proxy() transfers ownership to the caller, so this proxy is retained permanently for every streaming response. Destroy it when the background finalizer settles, as the websocket path does.
Suggested change
| task_proxy = create_proxy(finalizer_task) | |
| finalizer_task = run_in_background(finalize_request()) | |
| task_proxy = create_proxy(finalizer_task) | |
| finalizer_task.add_done_callback(lambda _: task_proxy.destroy()) | |
| wait_until(task_proxy) |
|
I'm Bonk, and I've done a quick review of your PR. Ensures streaming ASGI finalizers remain alive across
|
dom96
approved these changes
Sep 9, 2026
dom96
left a comment
Contributor
There was a problem hiding this comment.
AI comment might have a point, but rest looks good so approving.
Contributor
|
This is a duplicate of #249. I think it should be fixed in workerd: |
Contributor
Author
sounds good. Thanks for fixing that |
ryanking13
marked this pull request as draft
September 10, 2026 04:40
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.
While working on cloudflare/python-workers-examples#103, I noticed that finalizer_task is gc-ed and cleaned up improperly inside wait_until.
This fixes it by wrapping it with create_proxy.
Probably the long term solution is to land #90 and make
self.ctx.waitUntilandworkers.wait_untilwork exactly the same, but #90 requires JSPI which isn't available in 0.26.0a2, so it needs more discussion.