Skip to content

Commit 7e49c8c

Browse files
committed
fix(typescript-plugin): disconnect socket on error
1 parent 67bd6fc commit 7e49c8c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/typescript-plugin/lib/utils.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const pipes = new Map<string, 'unknown' | 'ready'>();
2626

2727
export const onSomePipeReadyCallbacks: (() => void)[] = [];
2828

29-
function watchNamedPipeReady(namedPipePath: string) {
29+
function waitingForNamedPipeServerReady(namedPipePath: string) {
3030
const socket = net.connect(namedPipePath);
3131
const start = Date.now();
3232
socket.on('connect', () => {
@@ -49,6 +49,10 @@ function watchNamedPipeReady(namedPipePath: string) {
4949
pipes.delete(namedPipePath);
5050
socket.end();
5151
});
52+
socket.on('timeout', () => {
53+
pipes.delete(namedPipePath);
54+
socket.end();
55+
});
5256
}
5357

5458
export function getNamedPipePath(projectKind: ts.server.ProjectKind.Configured | ts.server.ProjectKind.Inferred, key: number) {
@@ -68,14 +72,14 @@ export function getReadyNamedPipePaths() {
6872
}
6973
else if (!pipes.has(configuredPipe)) {
7074
pipes.set(configuredPipe, 'unknown');
71-
watchNamedPipeReady(configuredPipe);
75+
waitingForNamedPipeServerReady(configuredPipe);
7276
}
7377
if (pipes.get(inferredPipe) === 'ready') {
7478
inferredPipes.push(inferredPipe);
7579
}
7680
else if (!pipes.has(inferredPipe)) {
7781
pipes.set(inferredPipe, 'unknown');
78-
watchNamedPipeReady(inferredPipe);
82+
waitingForNamedPipeServerReady(inferredPipe);
7983
}
8084
}
8185
return {
@@ -104,11 +108,13 @@ export function connect(namedPipePath: string, timeout?: number) {
104108
pipes.delete(namedPipePath);
105109
cleanup();
106110
resolve('error');
111+
socket.end();
107112
};
108113
const onTimeout = () => {
109114
cleanup();
110115
resolve('timeout');
111-
}
116+
socket.end();
117+
};
112118
const cleanup = () => {
113119
socket.off('connect', onConnect);
114120
socket.off('error', onError);

0 commit comments

Comments
 (0)