Skip to content

Commit 42c20b4

Browse files
authored
Drain result pipe before disposing it on cancellation
1 parent 0e60b3c commit 42c20b4

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

  • src/client/testing/testController/common

src/client/testing/testController/common/utils.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,27 @@ export async function startRunResultNamedPipe(
102102
if (cancellationToken) {
103103
disposables.push(
104104
cancellationToken?.onCancellationRequested(() => {
105-
traceLog(`Test Result named pipe ${pipeName} cancelled`);
106-
disposable.dispose();
105+
traceLog(
106+
`Test Result named pipe ${pipeName} cancelled; draining buffered data before dispose`,
107+
);
108+
// Do NOT dispose the reader immediately. In the debug path, cancellation
109+
// fires as soon as the debug session terminates, but the result pipe may
110+
// still have buffered messages that have not been delivered to the
111+
// `reader.listen` callback yet. Disposing now would close the reader and
112+
// drop those pending results.
113+
//
114+
// The reader's `onClose` event (registered below) will fire once the
115+
// subprocess closes its end of the pipe and all buffered data has been
116+
// drained, and that handler will dispose. Use a safety timeout to force
117+
// disposal in case the pipe never closes naturally (e.g. subprocess hang).
118+
setTimeout(() => {
119+
if (disposables.length > 0) {
120+
traceVerbose(
121+
`Test Result named pipe ${pipeName} drain timeout, forcing dispose`,
122+
);
123+
disposable.dispose();
124+
}
125+
}, 5000);
107126
}),
108127
);
109128
}

0 commit comments

Comments
 (0)