Skip to content

Commit 16fc315

Browse files
committed
Catch socket close during protocol handshake
zlib errors can cause the protocol handshake to not reject (until the timeout).
1 parent f0bafa3 commit 16fc315

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/vscode/src/vs/server/entry.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { logger } from 'vs/server/node/logger';
66
import { enableCustomMarketplace } from 'vs/server/node/marketplace';
77
import { Vscode } from 'vs/server/node/server';
88

9-
setUnexpectedErrorHandler((error) => logger.warn(error instanceof Error ? error.message : error));
9+
setUnexpectedErrorHandler((error) => {
10+
logger.warn('Uncaught error', field('error', error instanceof Error ? error.message : error));
11+
});
1012
enableCustomMarketplace();
1113
proxyAgent.monkeyPatch(true);
1214

lib/vscode/src/vs/server/node/protocol.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,24 @@ export class Protocol extends PersistentProtocol {
5454
*/
5555
public handshake(): Promise<ConnectionTypeRequest> {
5656
this.logger.debug('Initiating handshake...');
57+
5758
return new Promise((resolve, reject) => {
59+
const cleanup = () => {
60+
handler.dispose();
61+
onClose.dispose();
62+
clearTimeout(timeout);
63+
};
64+
65+
const onClose = this.onSocketClose(() => {
66+
cleanup();
67+
this.logger.debug('Handshake failed');
68+
reject(new Error('Protocol socket closed unexpectedly'));
69+
});
70+
5871
const timeout = setTimeout(() => {
72+
cleanup();
5973
this.logger.debug('Handshake timed out');
60-
reject(new Error('protocol handshake timed out'));
74+
reject(new Error('Protocol handshake timed out'));
6175
}, 10000); // Matches the client timeout.
6276

6377
const handler = this.onControlMessage((rawMessage) => {
@@ -69,16 +83,14 @@ export class Protocol extends PersistentProtocol {
6983
case 'auth':
7084
return this.authenticate(message);
7185
case 'connectionType':
72-
handler.dispose();
73-
clearTimeout(timeout);
86+
cleanup();
7487
this.logger.debug('Handshake completed');
7588
return resolve(message);
7689
default:
7790
throw new Error('Unrecognized message type');
7891
}
7992
} catch (error) {
80-
handler.dispose();
81-
clearTimeout(timeout);
93+
cleanup();
8294
reject(error);
8395
}
8496
});

0 commit comments

Comments
 (0)