fix: scheduler can no longer yield if protobuf mutex is held#473
Merged
chris-olszewski merged 9 commits intoJul 5, 2026
Conversation
chris-olszewski
force-pushed
the
olszewski/fix_protobuf_blocking_cmd_creation
branch
from
July 2, 2026 15:09
3ba74cd to
767fa5d
Compare
chris-olszewski
marked this pull request as ready for review
July 2, 2026 16:51
GregoryTravis
approved these changes
Jul 2, 2026
| end | ||
| assert_thread_blocking_fiber_count(scheduler, 1) | ||
| assert_empty after_mutex | ||
| assert_empty drain_result |
Contributor
There was a problem hiding this comment.
Are there any conditions where this could return something else? Just making sure I understand.
Member
Author
There was a problem hiding this comment.
Since we're holding onto our fake protobuf mutex, we want to verify that this never emits any "commands". If this was ever non-empty that would mean we emitted commands even under the scenario we're trying to prevent.
Co-authored-by: Gregory Michael Travis <greg.m.travis@gmail.com>
chris-olszewski
force-pushed
the
olszewski/fix_protobuf_blocking_cmd_creation
branch
from
July 5, 2026 19:21
253e67b to
2ce894a
Compare
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.
What was changed
Scheduler#run_until_all_yieldedwill no longer return if the Google protobuf mutex is held.This is done by inspecting
blockcalls to see if the blocker is a mutex withgoogle/protobufin the path. This is more fragile than desired (as shown by how we test this behavior), but is already how we allowlist this mutex usage inIllegalWorkflowCallValidatorso we are at least consistent in what we allow.These
blockcalls that come from theprotobufmutex will be tracked additionally and anyFiberthat is blocked because of this will prevent us from considering that all ready fibers have been resumed.Why?
We special case allow mutex usage from
protobufin the workflow as it is "safe" usage (as in it cannot cause non-determinism, it guards a cache to avoid unnecessary allocations). This is still not fully safe as if the workflow future is blocked waiting for this call,Scheduler#run_until_all_yieldedcan return even if there is additional work to do for this activation once the protobuf mutex is acquired. This resulted in "partial" workflow activations that could not be replayed consistently.The issue is that the mutex used by protobuf is process wide so a worker that executes both activities and workflows will have the workflow threads fight with the activity threads for the mutex. This along with general CPU pressure could increase the chance of this mutex having contention.
We cannot warm this cache as it is backed by WeakMap.
Checklist
Closes [Bug] Sync primitives can lead to un-replayable workflow history. #464
How was this tested:
Added some fairly forced regression tests. Added some unit tests for our scheduler directly since those are the most worrisome changes.
N/A