Skip to content

Commit df61e19

Browse files
committed
add in timeouts
1 parent 6638e15 commit df61e19

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,15 @@ export class RoslynLanguageServer {
554554
childProcess = cp.spawn(serverPath, args, cpOptions);
555555
}
556556

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+
557562
// The server process will create the named pipe used for communcation. Wait for it to be created,
558563
// and listen for the server to pass back the connection information via stdout.
559564
const namedPipeConnectionPromise = new Promise<NamedPipeInformation>((resolve) => {
565+
_channel.appendLine('waiting for named pipe information from server...');
560566
childProcess.stdout.on('data', (data: { toString: (arg0: any) => any }) => {
561567
const result: string = isString(data) ? data : data.toString(RoslynLanguageServer.encoding);
562568
_channel.append('[stdout] ' + result);
@@ -572,8 +578,11 @@ export class RoslynLanguageServer {
572578
});
573579

574580
// 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+
}
577586

578587
const socketPromise = new Promise<net.Socket>((resolve) => {
579588
_channel.appendLine('attempting to connect client to server...');
@@ -583,7 +592,15 @@ export class RoslynLanguageServer {
583592
});
584593
});
585594

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+
587604
return {
588605
reader: new SocketMessageReader(socket, RoslynLanguageServer.encoding),
589606
writer: new SocketMessageWriter(socket, RoslynLanguageServer.encoding),

0 commit comments

Comments
 (0)