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

Connection State Recovery #464

Open
HeroOfOdyssey opened this issue Oct 16, 2024 · 4 comments
Open

Connection State Recovery #464

HeroOfOdyssey opened this issue Oct 16, 2024 · 4 comments

Comments

@HeroOfOdyssey
Copy link

I think there's a critical issue in connection state recovery documentation. The fact that the server must emit an event for it to be successful is documented, but unfortunately, I only saw that tidbit after hours of debugging. I think the "For the recovery to succeed, the server must send at least one event, in order to initialize the offset on the client side." text shouldn't solely be under "how it works under the hood" because that's critical information for implementation of connection state recovery, and is relevant to anyone who is implementing it, not just those who are curious about how it works. I think it should be under the "usage" section or the "disclaimer" section and be in a yellow or red box, not a grey "note" box because it's a little bit more than a note. An additional "Connection State Recovery will NOT be successful unless the client has received at least one event from the server" warning would be greatly beneficial.

@HeroOfOdyssey
Copy link
Author

#465
Made a pull request with the change. currently its a tip element but maybe it should be a caution element

@JosuaMnl
Copy link

I don’t understand this part: 'Connection State Recovery will NOT be successful unless the client has received at least one event from the server.' When I tried the tutorial in step 6 (Tutorial Step 6-Connection state recovery), when tab browser A reconnects, I can’t receive the message that tab browser B sent while tab browser A was disconnected. However, when I disconnect the socket using socket.io.engine.close(), it reestablishes the connection automatically and receives the message. Why? I’m confused because the tutorial doesn’t explain this.

@HeroOfOdyssey
Copy link
Author

I don’t understand this part: 'Connection State Recovery will NOT be successful unless the client has received at least one event from the server.' When I tried the tutorial in step 6 (Tutorial Step 6-Connection state recovery), when tab browser A reconnects, I can’t receive the message that tab browser B sent while tab browser A was disconnected. However, when I disconnect the socket using socket.io.engine.close(), it reestablishes the connection automatically and receives the message. Why? I’m confused because the tutorial doesn’t explain this.

Interestingly I never found any of those tutorial pages when I first got started with using Socket.IO, I've only seen the guide pages and api docs. But the guide page mentioned in the PR I linked does explain it fully (https://socket.io/docs/v4/connection-state-recovery)

I agree the page you have linked is also outdated documentation and examples on the subject. Essentially, Socket.IO doesn't care to recover state if it was closed expectedly through socket.disconnect, since that is a manually triggered event which is emitted to server, so the server has no reason to attempt recovery. Connection State Recovery only occurs for unexpected disconnections such as the underlying engine closing. Also note that in order for it to be successful, at least one message must be received (maybe sent? unsure).

I think the example you linked should have the io client initiated with reconnection flag set to false (in addition to using socket.io.engine.close in place of socket.disconnect) so that it doesn't automatically reconnect, otherwise setting the button to say "reconnect" is pointless, as reconnection is automatically attempted and successful as soon as underlying engine is closed. also maybe two buttons, one for manual disconnection and one for unexpected disconnection could work well to demonstrate the principal.

@z3278304322
Copy link

I don’t understand this part: 'Connection State Recovery will NOT be successful unless the client has received at least one event from the server.' When I tried the tutorial in step 6 (Tutorial Step 6-Connection state recovery), when tab browser A reconnects, I can’t receive the message that tab browser B sent while tab browser A was disconnected. However, when I disconnect the socket using socket.io.engine.close(), it reestablishes the connection automatically and receives the message. Why? I’m confused because the tutorial doesn’t explain this.

I met this problem as well, have u figured it out?

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

3 participants