@@ -554,9 +554,15 @@ export class RoslynLanguageServer {
554
554
childProcess = cp . spawn ( serverPath , args , cpOptions ) ;
555
555
}
556
556
557
+ // Timeout promise used to time out the connection process if it takes too long.
558
+ const timeout = new Promise < undefined > ( ( resolve ) => {
559
+ RAL ( ) . timer . setTimeout ( resolve , 10000 ) ;
560
+ } ) ;
561
+
557
562
// The server process will create the named pipe used for communcation. Wait for it to be created,
558
563
// and listen for the server to pass back the connection information via stdout.
559
564
const namedPipeConnectionPromise = new Promise < NamedPipeInformation > ( ( resolve ) => {
565
+ _channel . appendLine ( 'waiting for named pipe information from server...' ) ;
560
566
childProcess . stdout . on ( 'data' , ( data : { toString : ( arg0 : any ) => any } ) => {
561
567
const result : string = isString ( data ) ? data : data . toString ( RoslynLanguageServer . encoding ) ;
562
568
_channel . append ( '[stdout] ' + result ) ;
@@ -572,8 +578,11 @@ export class RoslynLanguageServer {
572
578
} ) ;
573
579
574
580
// Wait for the server to send back the name of the pipe to connect to.
575
- _channel . appendLine ( 'waiting for named pipe information from server...' ) ;
576
- const pipeConnectionInfo = await namedPipeConnectionPromise ;
581
+ // If it takes too long it will timeout and throw an error.
582
+ const pipeConnectionInfo = await Promise . race ( [ namedPipeConnectionPromise , timeout ] ) ;
583
+ if ( pipeConnectionInfo === undefined ) {
584
+ throw new Error ( 'Timeout. Named pipe information not received from server.' ) ;
585
+ }
577
586
578
587
const socketPromise = new Promise < net . Socket > ( ( resolve ) => {
579
588
_channel . appendLine ( 'attempting to connect client to server...' ) ;
@@ -583,7 +592,15 @@ export class RoslynLanguageServer {
583
592
} ) ;
584
593
} ) ;
585
594
586
- const socket = await socketPromise ;
595
+ // Wait for the client to connect to the named pipe.
596
+ // If it takes too long it will timeout and throw an error.
597
+ const socket = await Promise . race ( [ socketPromise , timeout ] ) ;
598
+ if ( socket === undefined ) {
599
+ throw new Error (
600
+ 'Timeout. Client cound not connect to server via named pipe: ' + pipeConnectionInfo . pipeName
601
+ ) ;
602
+ }
603
+
587
604
return {
588
605
reader : new SocketMessageReader ( socket , RoslynLanguageServer . encoding ) ,
589
606
writer : new SocketMessageWriter ( socket , RoslynLanguageServer . encoding ) ,
0 commit comments