in src/panels/TcpDumpPanel.ts [336:407]
private async handleStopCapture(node: NodeName, capture: string, webview: MessageSink<ToWebViewMsgDef>) {
const runningCaptures = await this.getRunningCaptures(node);
if (failed(runningCaptures)) {
webview.postStopCaptureResponse({
node,
succeeded: false,
errorMessage: `Failed to determine running captures:\n${runningCaptures.error}`,
capture: null,
});
return;
}
const captureProcess = runningCaptures.result.find((p) => p.capture === capture);
if (!captureProcess) {
webview.postStopCaptureResponse({
node,
succeeded: false,
errorMessage: `Unable to find running capture ${capture}. Found: ${runningCaptures.result
.map((p) => p.capture)
.join(",")}`,
capture: null,
});
return;
}
const podCommand = `/bin/sh -c "kill ${captureProcess.pid}"`;
const killOutput = await getExecOutput(
this.kubectl,
this.kubeConfigFilePath,
debugPodNamespace,
getPodName(node),
podCommand,
);
if (failed(killOutput)) {
webview.postStopCaptureResponse({
node,
succeeded: false,
errorMessage: `Failed to kill tcpdump process ${captureProcess.pid}:\n${killOutput.error}`,
capture: null,
});
return;
}
const completedCaptures = await this.getCompletedCaptures(node, []);
if (failed(completedCaptures)) {
webview.postStopCaptureResponse({
node,
succeeded: false,
errorMessage: `Failed to read completed captures:\n${completedCaptures.error}`,
capture: null,
});
return;
}
const stoppedCapture = completedCaptures.result.find((c) => c.name === capture);
if (!stoppedCapture) {
webview.postStopCaptureResponse({
node,
succeeded: false,
errorMessage: `Cannot find capture file for ${capture}`,
capture: null,
});
return;
}
webview.postStopCaptureResponse({
node,
succeeded: true,
errorMessage: null,
capture: stoppedCapture,
});
}