Skip to content

Commit e9526ed

Browse files
wahaha1223steipete
authored andcommitted
fix(linux-canvas): report socket watcher fallback
1 parent 08fc4f5 commit e9526ed

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

‎extensions/linux-canvas/src/socket-path.test.ts‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
import { EventEmitter } from "node:events";
12
import fs from "node:fs";
23
import net from "node:net";
34
import os from "node:os";
45
import path from "node:path";
5-
import { afterEach, describe, expect, it } from "vitest";
6-
import { linuxCanvasSocketExists } from "./socket-path.js";
6+
import { afterEach, describe, expect, it, vi } from "vitest";
7+
import { linuxCanvasSocketExists, watchLinuxCanvasSocket } from "./socket-path.js";
8+
9+
const loggerMocks = vi.hoisted(() => ({ warn: vi.fn() }));
10+
11+
vi.mock("openclaw/plugin-sdk/runtime-env", () => ({
12+
createSubsystemLogger: () => loggerMocks,
13+
}));
714

815
const tempDirs: string[] = [];
916

1017
afterEach(() => {
18+
vi.restoreAllMocks();
19+
loggerMocks.warn.mockReset();
1120
for (const dir of tempDirs.splice(0)) {
1221
fs.rmSync(dir, { recursive: true, force: true });
1322
}
@@ -41,4 +50,31 @@ describe("Linux Canvas socket availability", () => {
4150
expect(linuxCanvasSocketExists(socketPath)).toBe(false);
4251
},
4352
);
53+
54+
it("reports synchronous and asynchronous watcher failures before falling back to polling", () => {
55+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-linux-canvas-watch-"));
56+
tempDirs.push(directory);
57+
const socketPath = path.join(directory, "canvas.sock");
58+
const watcher = Object.assign(new EventEmitter(), { close: vi.fn() });
59+
const watch = vi
60+
.spyOn(fs, "watch")
61+
.mockImplementationOnce(() => watcher as unknown as fs.FSWatcher)
62+
.mockImplementationOnce(() => {
63+
throw new Error("EMFILE");
64+
});
65+
66+
const stop = watchLinuxCanvasSocket(socketPath, vi.fn());
67+
watcher.emit("error", new Error("ENOSPC"));
68+
expect(loggerMocks.warn).toHaveBeenCalledWith(
69+
expect.stringContaining("continuing with availability polling: Error: ENOSPC"),
70+
);
71+
stop();
72+
expect(watcher.close).toHaveBeenCalledOnce();
73+
74+
expect(() => watchLinuxCanvasSocket(socketPath, vi.fn())).not.toThrow();
75+
expect(loggerMocks.warn).toHaveBeenCalledWith(
76+
expect.stringContaining("continuing with availability polling: Error: EMFILE"),
77+
);
78+
expect(watch).toHaveBeenCalledTimes(2);
79+
});
4480
});

‎extensions/linux-canvas/src/socket-path.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
4+
5+
const log = createSubsystemLogger("linux-canvas");
6+
7+
function reportSocketWatchError(directory: string, error: unknown): void {
8+
log.warn(
9+
`linux canvas socket watcher unavailable for ${directory}; continuing with availability polling: ${String(error)}`,
10+
);
11+
}
312

413
export function resolveLinuxCanvasSocketPath(
514
env: NodeJS.ProcessEnv = process.env,
@@ -35,9 +44,10 @@ export function watchLinuxCanvasSocket(socketPath: string, onChange: () => void)
3544
onChange();
3645
}
3746
});
38-
watcher.on("error", () => {});
47+
watcher.on("error", (error) => reportSocketWatchError(directory, error));
3948
return () => watcher.close();
40-
} catch {
49+
} catch (error) {
50+
reportSocketWatchError(directory, error);
4151
return () => {};
4252
}
4353
}

0 commit comments

Comments
 (0)