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

[web][ff] web socket breaks when changing network #194284

Closed
akosyakov opened this issue Sep 27, 2023 · 11 comments · Fixed by #194436
Closed

[web][ff] web socket breaks when changing network #194284

akosyakov opened this issue Sep 27, 2023 · 11 comments · Fixed by #194436
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders remote-connection Issues about the remote connection verified Verification succeeded
Milestone

Comments

@akosyakov
Copy link
Contributor

akosyakov commented Sep 27, 2023

At Gitpod we received bug requests that in FireFox (117-118) VS Code Web (1.82) sometimes became unresponsive. See Loom for what unresponsive means.

It is hard to reproduce, but I was able with following:

  1. Leave FF tab in the background.
  2. Trigger reconnects by toggling your wifi for instance.
  3. After a while come back to FF tab.

Debugging web part showed that frontend is keep asking to replay missing messages, but server keeps replaying with the same message. Unfortunately I was not able to debug the server part.

@akosyakov
Copy link
Contributor Author

akosyakov commented Sep 27, 2023

It is worth to mention that we observed this issue also without reconnection as well. Would maybe make sense as a safeguard to cycle a web socket if after replay the first replayed message don't satisfy this criteria:

if (msg.id !== this._incomingMsgId + 1) {
Otherwise it goes to loop forever?

@akosyakov
Copy link
Contributor Author

akosyakov commented Sep 28, 2023

I was able to reproduce it reliably with VS Code Server from sources by toggling VPN exit nodes. I've enabled server side diagnostics and noticed that server gets read and webSocketNodeSocketReadData events after toggling, but there are not more protocolHeaderRead and protocolMessageRead diagnostic traces. This loop does not seem to hit:

while (this._incomingData.byteLength >= this._state.readLen) {

cc @alexdima does it ring any bell? Would it help if i share such traces?

EDIT: I also confirmed that it only happens with FireFox, in case of Chrome it keeps working.

@akosyakov
Copy link
Contributor Author

akosyakov commented Sep 28, 2023

Here are traces one from Chrome and another from FireFox with the same test. You can see that at the end of FF log there are no anymore tracing for protocolHeaderRead and protocolMessageRead. (just a note I disabled compression while testing it here but it did not change results)

server.chrome.log
server.ff.log

EDIT: It is interesting that in case of FF protocolHeaderRead does not have a valid message type after changing VPN. If I compare to previous header, it seems everything is shifted, like there are additional bytes which corrupts the header. In my case it is always 801229866761

@akosyakov akosyakov changed the title [web][ff] web socket is stuck in replay loop [web][ff] web socket is stuck Sep 28, 2023
akosyakov added a commit to gitpod-io/openvscode-server that referenced this issue Sep 28, 2023
@akosyakov akosyakov changed the title [web][ff] web socket is stuck [web][ff] web socket breaks when changing network Sep 28, 2023
@akosyakov
Copy link
Contributor Author

I've tested a workaround that effectively resolves the issue; you can view the changes in our fork [1]. Should I send a pull request?

I've also filed a bug report for Firefox: 1855692.

@alexdima
Copy link
Member

Hmm, it's possible Firefox is sending a control opcode that we don't handle well https://datatracker.ietf.org/doc/html/rfc6455#section-5.2

@alexdima
Copy link
Member

@akosyakov If you still have an easy repro, could you perhaps log the opcode:

diff --git a/src/vs/base/parts/ipc/node/ipc.net.ts b/src/vs/base/parts/ipc/node/ipc.net.ts
index ed30467961b..e1f14c2361a 100644
--- a/src/vs/base/parts/ipc/node/ipc.net.ts
+++ b/src/vs/base/parts/ipc/node/ipc.net.ts
@@ -390,6 +390,8 @@ export class WebSocketNodeSocket extends Disposable implements ISocket, ISocketT
                                const firstByte = peekHeader.readUInt8(0);
                                const finBit = (firstByte & 0b10000000) >>> 7;
                                const rsv1Bit = (firstByte & 0b01000000) >>> 6;
+                               const opcode = (firstByte & 0b00001111);
+                               console.log(`opcode: ${opcode}`);
                                const secondByte = peekHeader.readUInt8(1);
                                const hasMask = (secondByte & 0b10000000) >>> 7;
                                const len = (secondByte & 0b01111111);

@akosyakov
Copy link
Contributor Author

akosyakov commented Sep 28, 2023

@alexdima here is output with FF:
Screenshot 2023-09-28 at 15 54 22

opcode 9 reliably happens when i toggle exit nodes.

Output with Chrome is different:
Screenshot 2023-09-28 at 16 13 04

jeanp413 added a commit to jeanp413/vscode that referenced this issue Sep 28, 2023
@jeanp413
Copy link
Contributor

Created a PR fixing it #194436 cc @alexdima

@roblourens roblourens assigned alexdima and unassigned roblourens Sep 28, 2023
jeanp413 added a commit to jeanp413/vscode that referenced this issue Sep 29, 2023
@akosyakov
Copy link
Contributor Author

Thank you both! I confirm that handling ping control code resolves the issue. @alexdima I verified that @jeanp413's PR work both with Chrome and FireFox.

akosyakov pushed a commit to gitpod-io/openvscode-server that referenced this issue Sep 29, 2023
akosyakov pushed a commit to gitpod-io/openvscode-server that referenced this issue Sep 29, 2023
@alexdima alexdima added this to the October 2023 milestone Sep 29, 2023
@alexdima alexdima added bug Issue identified by VS Code Team member as probable bug remote-connection Issues about the remote connection labels Sep 29, 2023
@alexdima
Copy link
Member

Thank you! ❤️

@VSCodeTriageBot VSCodeTriageBot added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Sep 29, 2023
@TylerLeonhardt TylerLeonhardt added the verified Verification succeeded label Sep 29, 2023
@TylerLeonhardt
Copy link
Member

Marking as verified due to @akosyakov's confirmation.

jeanp413 added a commit to gitpod-io/openvscode-server that referenced this issue Oct 3, 2023
filiptronicek pushed a commit to gitpod-io/openvscode-server that referenced this issue Oct 4, 2023
filiptronicek pushed a commit to gitpod-io/openvscode-server that referenced this issue Oct 12, 2023
Alex0007 pushed a commit to Alex0007/vscode that referenced this issue Oct 26, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders remote-connection Issues about the remote connection verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants