Skip to content

Conversation

@tomlarkworthy
Copy link
Contributor

@tomlarkworthy tomlarkworthy commented Jan 3, 2026

When using Observable runtime v6.0.0+, generators with undefined initial values would deadlock when their upstream dependencies changed. The runtime waits for the old generator to settle before starting the new one, but the pending promise would never resolve.

The fix converts observe() from an async function* to a manual async iterator, allowing return() to immediately reject pending promises without waiting for them to settle first.

port of observablehq/stdlib#399, addresses issue raised here observablehq/runtime#376

… deadlock

When using Observable runtime v6.0.0+, generators with undefined initial
values would deadlock when their upstream dependencies changed. The runtime
waits for the old generator to settle before starting the new one, but
the pending promise would never resolve.

The fix converts observe() from an async function* to a manual async
iterator, allowing return() to immediately reject pending promises
without waiting for them to settle first.

Adds unit test for promise rejection and integration test reproducing
the deadlock scenario with Generators.input and the Observable runtime.
@tomlarkworthy tomlarkworthy changed the title fix(generators): reject pending promises to prevent runtime deadlock fix(generators): reject pending promises to prevent runtime deadlock (NOT MERGE READY) Jan 3, 2026
Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you! 👍 This looks about right to me! I’ll probably make some style changes. I agree we need to opt-out of the async generator function so that we can reject the pending promise when the generator is return’ed or throw’ed.

@tomlarkworthy tomlarkworthy changed the title fix(generators): reject pending promises to prevent runtime deadlock (NOT MERGE READY) fix(generators): reject pending promises to prevent runtime deadlock Jan 6, 2026
Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed up Generators.queue, too.

@mbostock mbostock merged commit a043520 into observablehq:main Jan 7, 2026
1 check passed
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.

2 participants