Skip to content

Fix race condition in SyncMessagePort#327

Merged
nex3 merged 5 commits intosass:mainfrom
ntkme:fix-sync-message-port
Sep 5, 2024
Merged

Fix race condition in SyncMessagePort#327
nex3 merged 5 commits intosass:mainfrom
ntkme:fix-sync-message-port

Conversation

@ntkme
Copy link
Contributor

@ntkme ntkme commented Aug 28, 2024

Fixes #326.

The idea of this PR is that instead of having only three states:

  • AwaitingMessage = 0
  • MessageSent = 1
  • Closed = 2

This PR uses four states:

  • AwaitingMessage = 0b00
  • MessageSent = 0b01
  • Closed & AwaitingMessage = 0b10
  • Closed & MessageSent = 0b11

This allows receiveMessage() to correctly consume the very last message.

Copy link
Contributor

@nex3 nex3 left a comment

Choose a reason for hiding this comment

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

Would it be possible to add a more direct test case for this to sync-message-port.test.ts? Or is the existing flaky failure the best we can do to exercise it?

@ntkme ntkme requested a review from nex3 August 31, 2024 16:59
@ntkme
Copy link
Contributor Author

ntkme commented Aug 31, 2024

Would it be possible to add a more direct test case for this to sync-message-port.test.ts? Or is the existing flaky failure the best we can do to exercise it?

I've added a test as it turns out it is much more easier to reproduce it with a test case. On my local setup, the added test case 100% fails on main branch without adjusting timing artificially.

ntkme and others added 2 commits September 3, 2024 14:04
Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
@nex3 nex3 merged commit 9076adb into sass:main Sep 5, 2024
@ntkme ntkme deleted the fix-sync-message-port branch September 5, 2024 23:04
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.

Unexpected exception thrown due to race condition in SyncMessagePort

2 participants