Skip to content

Commit 0b9af6e

Browse files
committed
Initiate connection handshake from server
This way the connection can be initiated by either side. It looks like sometimes the initial message from the client is lost (it never makes it into the onControlMessage callback) but I'm still not sure why or if that is preventable. Also added a timeout on the server end to clean things up in case the client never responds.
1 parent c63dc3a commit 0b9af6e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ci/dev/vscode.patch

+13-2
Original file line numberDiff line numberDiff line change
@@ -2478,10 +2478,10 @@ index 0000000000000000000000000000000000000000..3d428a57d31f29c40f9c3ce45f715b44
24782478
+};
24792479
diff --git a/src/vs/server/node/protocol.ts b/src/vs/server/node/protocol.ts
24802480
new file mode 100644
2481-
index 0000000000000000000000000000000000000000..523fcd3186d92799bc50e33a72832bd443b2945b
2481+
index 0000000000000000000000000000000000000000..0d9310038c0ca378579652d89bc8ac84924213db
24822482
--- /dev/null
24832483
+++ b/src/vs/server/node/protocol.ts
2484-
@@ -0,0 +1,80 @@
2484+
@@ -0,0 +1,91 @@
24852485
+import { field } from '@coder/logger';
24862486
+import * as net from 'net';
24872487
+import { VSBuffer } from 'vs/base/common/buffer';
@@ -2518,6 +2518,11 @@ index 0000000000000000000000000000000000000000..523fcd3186d92799bc50e33a72832bd4
25182518
+ public handshake(): Promise<ConnectionTypeRequest> {
25192519
+ logger.trace('Protocol handshake', field('token', this.options.reconnectionToken));
25202520
+ return new Promise((resolve, reject) => {
2521+
+ const timeout = setTimeout(() => {
2522+
+ logger.error('Handshake timed out', field('token', this.options.reconnectionToken));
2523+
+ reject(new Error("timed out"));
2524+
+ }, 10000); // Matches the client timeout.
2525+
+
25212526
+ const handler = this.onControlMessage((rawMessage) => {
25222527
+ try {
25232528
+ const raw = rawMessage.toString();
@@ -2528,15 +2533,21 @@ index 0000000000000000000000000000000000000000..523fcd3186d92799bc50e33a72832bd4
25282533
+ return this.authenticate(message);
25292534
+ case 'connectionType':
25302535
+ handler.dispose();
2536+
+ clearTimeout(timeout);
25312537
+ return resolve(message);
25322538
+ default:
25332539
+ throw new Error('Unrecognized message type');
25342540
+ }
25352541
+ } catch (error) {
25362542
+ handler.dispose();
2543+
+ clearTimeout(timeout);
25372544
+ reject(error);
25382545
+ }
25392546
+ });
2547+
+
2548+
+ // Kick off the handshake in case we missed the client's opening shot.
2549+
+ // TODO: Investigate why that message seems to get lost.
2550+
+ this.authenticate();
25402551
+ });
25412552
+ }
25422553
+

0 commit comments

Comments
 (0)