Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the order of messages guaranteed? #542

Closed
bitliner opened this issue Aug 7, 2015 · 4 comments
Closed

Is the order of messages guaranteed? #542

bitliner opened this issue Aug 7, 2015 · 4 comments

Comments

@bitliner
Copy link

bitliner commented Aug 7, 2015

I did not find it explicitly in the RFC.

Is the order of operations guaranteed?

In other words

if clients do

// first op - client 1
.send(1)

// second op - client 2
.send(2)

then the receiver always receives

1
2

and never

2
1

Could you confirm it?

@jondubois
Copy link
Contributor

TCP itself offers in-order, exactly-once delivery guarantee so yes WS also does by extension. HTTP doesn't provide this guarantee because HTTP requests may be spread over multiple TCP connections (and this negates the guarantee). Since a WebSocket uses a single TCP connection, this guarantee is maintained.

@devinivy
Copy link

@jondubois 👍 nicely said– thanks.

@patrickelectric
Copy link

patrickelectric commented Aug 13, 2024

It appears to be possible: https://x.com/ThePrimeagen/status/1796262882721587362

@jondubois
Copy link
Contributor

jondubois commented Aug 13, 2024

@patrickelectric I believe the issue is specific to that implementation itself awaiting on blob.arrayBuffer() which can take longer to resolve for some messages than others. So the messages arrive in-order but they finish processing in a potentially different order. It's the exact reason why SocketCluster focuses on for-await-of loops. So it shouldn't be an issue with SC if you use it as documented.

With a for-await-of loop, each iteration blocks on each await so you can't end up with such race conditions, even if you add some additional async processing to each message.

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

No branches or pull requests

5 participants