Skip to content

Conversation

@mcheshkov
Copy link
Contributor

Check List

  • Tests have been run in packages where changes made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Description of Changes Made (if issue reference is not provided)

Before this there were a race between setTimeout in sendMessage and close. Even for a good citizen, that calls unsubscribe() and awaits result there were no synchronization between unsubscribe adding message to messageQueue and restarting timer, and actually sending this message to WebSocket. When close() is called close frame is sent immediately to WebSocket. If at that moment messageQueue is not empty, and timer is armed it can wake up, and discover socket in CLOSING state: send side closed, recv side open.

For now - just flush everything queued, and send close frame after, so it would look like close was queued after. More complete solution is to add synchronization between unsubscribe call and sending message, or even receiving ack for it.

Before this there were a race between `setTimeout` in `sendMessage` and `close`.
Even for a good citizen, that calls `unsubscribe()` and awaits result there were no synchronization between unsubscribe adding message to `messageQueue` and restarting timer, and actually sending this message to WebSocket.
When `close()` is called close frame is sent immediately to WebSocket. If at that moment messageQueue is not empty, and timer is armed it can wake up, and discover socket in CLOSING state: send side closed, recv side open.

For now - just flush everything queued, and send close frame after, so it would look like close was queued after.
More complete solution is to add synchronization between unsubscribe call and sending message, or even receiving ack for it.
Copy link
Member

@KSDaemon KSDaemon left a comment

Choose a reason for hiding this comment

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

👍🏻 LGTM!

@mcheshkov mcheshkov marked this pull request as ready for review January 15, 2025 13:10
@mcheshkov mcheshkov requested a review from a team as a code owner January 15, 2025 13:10
@mcheshkov
Copy link
Contributor Author

The only failure is Firebolt integration tests, they are broken right now and is being diagnosted. I'll land this as is, to unstuck CI checks in other PRs.

@mcheshkov mcheshkov merged commit d9bc147 into master Jan 15, 2025
28 of 29 checks passed
@mcheshkov mcheshkov deleted the ws-transport-close-race branch January 15, 2025 13:15
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.

3 participants