Fix macOS exec-host JSONL socket deadlock

This commit is contained in:
skernelx
2026-04-02 19:10:35 +08:00
committed by Peter Steinberger
parent c4fb15e492
commit 0e3cc12900
2 changed files with 38 additions and 1 deletions

View File

@@ -54,6 +54,42 @@ describe.runIf(process.platform !== "win32")("requestJsonlSocket", () => {
});
});
it("half-closes the write side after sending the request line", async () => {
await withTempDir({ prefix: "openclaw-jsonl-socket-" }, async (dir) => {
const socketPath = path.join(dir, "socket.sock");
const server = net.createServer((socket) => {
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString("utf8");
});
socket.on("end", () => {
expect(buffer).toBe('{"hello":"world"}\n');
socket.end('{"type":"done","value":7}\n');
});
});
const listening = await listenOnSocket(server, socketPath);
if (!listening) {
return;
}
try {
await expect(
requestJsonlSocket({
socketPath,
payload: '{"hello":"world"}',
timeoutMs: 500,
accept: (msg) => {
const value = msg as { type?: string; value?: number };
return value.type === "done" ? (value.value ?? null) : undefined;
},
}),
).resolves.toBe(7);
} finally {
server.close();
}
});
});
it("returns null on timeout and on socket errors", async () => {
await withTempDir({ prefix: "openclaw-jsonl-socket-" }, async (dir) => {
const socketPath = path.join(dir, "socket.sock");

View File

@@ -30,7 +30,8 @@ export async function requestJsonlSocket<T>(params: {
client.on("error", () => finish(null));
client.connect(socketPath, () => {
client.write(`${payload}\n`);
// The macOS exec host can wait for EOF before responding, so finish writing.
client.end(`${payload}\n`);
});
client.on("data", (data) => {
buffer += data.toString("utf8");