File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import { logger } from 'vs/server/node/logger';
66import { enableCustomMarketplace } from 'vs/server/node/marketplace' ;
77import { 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+ } ) ;
1012enableCustomMarketplace ( ) ;
1113proxyAgent . monkeyPatch ( true ) ;
1214
Original file line number Diff line number Diff 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 } ) ;
You can’t perform that action at this time.
0 commit comments