Skip to content

Commit 00791fd

Browse files
fix read streams blocking node threads (#24652)
fixes #24594 fixes #24507 Co-authored-by: Eleanor Boyd <[email protected]>
1 parent c924321 commit 00791fd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/client/common/pipes/namedPipes.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CancellationError, CancellationToken, Disposable } from 'vscode';
1212
import { traceVerbose } from '../../logging';
1313
import { isWindows } from '../utils/platform';
1414
import { createDeferred } from '../utils/async';
15+
import { noop } from '../utils/misc';
1516

1617
const { XDG_RUNTIME_DIR } = process.env;
1718
export function generateRandomPipeName(prefix: string): string {
@@ -187,6 +188,13 @@ export async function createReaderPipe(pipeName: string, token?: CancellationTok
187188
} catch {
188189
// Intentionally ignored
189190
}
190-
const reader = fs.createReadStream(pipeName, { encoding: 'utf-8' });
191-
return new rpc.StreamMessageReader(reader, 'utf-8');
191+
const fd = await fs.open(pipeName, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
192+
const socket = new net.Socket({ fd });
193+
const reader = new rpc.SocketMessageReader(socket, 'utf-8');
194+
socket.on('close', () => {
195+
fs.close(fd).catch(noop);
196+
reader.dispose();
197+
});
198+
199+
return reader;
192200
}

0 commit comments

Comments
 (0)