mirror of https://git.tuxpa.in/a/code-server.git
Catch socket close during protocol handshake
zlib errors can cause the protocol handshake to not reject (until the timeout).
This commit is contained in:
parent
f0bafa387f
commit
16fc315afa
|
@ -6,7 +6,9 @@ import { logger } from 'vs/server/node/logger';
|
||||||
import { enableCustomMarketplace } from 'vs/server/node/marketplace';
|
import { enableCustomMarketplace } from 'vs/server/node/marketplace';
|
||||||
import { Vscode } from 'vs/server/node/server';
|
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();
|
enableCustomMarketplace();
|
||||||
proxyAgent.monkeyPatch(true);
|
proxyAgent.monkeyPatch(true);
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,24 @@ export class Protocol extends PersistentProtocol {
|
||||||
*/
|
*/
|
||||||
public handshake(): Promise<ConnectionTypeRequest> {
|
public handshake(): Promise<ConnectionTypeRequest> {
|
||||||
this.logger.debug('Initiating handshake...');
|
this.logger.debug('Initiating handshake...');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
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(() => {
|
const timeout = setTimeout(() => {
|
||||||
|
cleanup();
|
||||||
this.logger.debug('Handshake timed out');
|
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.
|
}, 10000); // Matches the client timeout.
|
||||||
|
|
||||||
const handler = this.onControlMessage((rawMessage) => {
|
const handler = this.onControlMessage((rawMessage) => {
|
||||||
|
@ -69,16 +83,14 @@ export class Protocol extends PersistentProtocol {
|
||||||
case 'auth':
|
case 'auth':
|
||||||
return this.authenticate(message);
|
return this.authenticate(message);
|
||||||
case 'connectionType':
|
case 'connectionType':
|
||||||
handler.dispose();
|
cleanup();
|
||||||
clearTimeout(timeout);
|
|
||||||
this.logger.debug('Handshake completed');
|
this.logger.debug('Handshake completed');
|
||||||
return resolve(message);
|
return resolve(message);
|
||||||
default:
|
default:
|
||||||
throw new Error('Unrecognized message type');
|
throw new Error('Unrecognized message type');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handler.dispose();
|
cleanup();
|
||||||
clearTimeout(timeout);
|
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue