Catch socket close during protocol handshake

zlib errors can cause the protocol handshake to not reject (until the
timeout).
This commit is contained in:
Asher 2021-04-20 15:48:24 -05:00
parent f0bafa387f
commit 16fc315afa
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 20 additions and 6 deletions

View File

@ -6,7 +6,9 @@ import { logger } from 'vs/server/node/logger';
import { enableCustomMarketplace } from 'vs/server/node/marketplace';
import { Vscode } from 'vs/server/node/server';
setUnexpectedErrorHandler((error) => logger.warn(error instanceof Error ? error.message : error));
setUnexpectedErrorHandler((error) => {
logger.warn('Uncaught error', field('error', error instanceof Error ? error.message : error));
});
enableCustomMarketplace();
proxyAgent.monkeyPatch(true);

View File

@ -54,10 +54,24 @@ export class Protocol extends PersistentProtocol {
*/
public handshake(): Promise<ConnectionTypeRequest> {
this.logger.debug('Initiating handshake...');
return new Promise((resolve, reject) => {
const cleanup = () => {
handler.dispose();
onClose.dispose();
clearTimeout(timeout);
};
const onClose = this.onSocketClose(() => {
cleanup();
this.logger.debug('Handshake failed');
reject(new Error('Protocol socket closed unexpectedly'));
});
const timeout = setTimeout(() => {
cleanup();
this.logger.debug('Handshake timed out');
reject(new Error('protocol handshake timed out'));
reject(new Error('Protocol handshake timed out'));
}, 10000); // Matches the client timeout.
const handler = this.onControlMessage((rawMessage) => {
@ -69,16 +83,14 @@ export class Protocol extends PersistentProtocol {
case 'auth':
return this.authenticate(message);
case 'connectionType':
handler.dispose();
clearTimeout(timeout);
cleanup();
this.logger.debug('Handshake completed');
return resolve(message);
default:
throw new Error('Unrecognized message type');
}
} catch (error) {
handler.dispose();
clearTimeout(timeout);
cleanup();
reject(error);
}
});