mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-05 14:21:32 +00:00
Fix macOS exec-host JSONL socket deadlock
This commit is contained in:
committed by
Peter Steinberger
parent
c4fb15e492
commit
0e3cc12900
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user