Skip to content

Commit

Permalink
fix read streams blocking node threads (#24652)
Browse files Browse the repository at this point in the history
fixes #24594 
fixes #24507

Co-authored-by: Eleanor Boyd <eleanorboyd@microsoft.com>
  • Loading branch information
karthiknadig and eleanorjboyd authored Dec 23, 2024
1 parent c924321 commit 00791fd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/client/common/pipes/namedPipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CancellationError, CancellationToken, Disposable } from 'vscode';
import { traceVerbose } from '../../logging';
import { isWindows } from '../utils/platform';
import { createDeferred } from '../utils/async';
import { noop } from '../utils/misc';

const { XDG_RUNTIME_DIR } = process.env;
export function generateRandomPipeName(prefix: string): string {
Expand Down Expand Up @@ -187,6 +188,13 @@ export async function createReaderPipe(pipeName: string, token?: CancellationTok
} catch {
// Intentionally ignored
}
const reader = fs.createReadStream(pipeName, { encoding: 'utf-8' });
return new rpc.StreamMessageReader(reader, 'utf-8');
const fd = await fs.open(pipeName, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
const socket = new net.Socket({ fd });
const reader = new rpc.SocketMessageReader(socket, 'utf-8');
socket.on('close', () => {
fs.close(fd).catch(noop);
reader.dispose();
});

return reader;
}

0 comments on commit 00791fd

Please sign in to comment.