Skip to content

Commit 8dfee38

Browse files
fix(server): a directory no longer resolves as the resource monitor binary (pingdotgg#16838)
Co-authored-by: Yash Singh <[email protected]>
1 parent 8f43ced commit 8dfee38

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎apps/server/src/resourceTelemetry/ResourceMonitorBinary.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ describe("ResourceMonitorBinary", () => {
115115
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
116116
);
117117

118+
it.effect("rejects a directory override", () =>
119+
Effect.gen(function* () {
120+
const fileSystem = yield* FileSystem.FileSystem;
121+
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
122+
prefix: "t3-resource-monitor-binary-",
123+
});
124+
125+
const service = yield* ResourceMonitorBinary.make().pipe(
126+
Effect.provide(ServerConfig.layerTest(process.cwd(), baseDir)),
127+
Effect.provideService(HostProcess.Platform, "win32"),
128+
Effect.provideService(HostProcess.Architecture, "arm64"),
129+
Effect.provideService(HostProcess.Environment, {
130+
T3CODE_RESOURCE_MONITOR_PATH: baseDir,
131+
}),
132+
);
133+
const error = yield* Effect.flip(service.resolve);
134+
135+
assert.instanceOf(error, ResourceMonitorBinary.ResourceMonitorBinaryNotExecutable);
136+
assert.equal(error.path, baseDir);
137+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
138+
);
139+
118140
it.effect("rejects unsupported platform and architecture pairs", () =>
119141
Effect.gen(function* () {
120142
const fileSystem = yield* FileSystem.FileSystem;

‎apps/server/src/resourceTelemetry/ResourceMonitorBinary.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,14 @@ export const make = Effect.fn("resourceTelemetry.resourceMonitorBinary.make")(fu
196196
const exists = yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false));
197197
if (!exists) continue;
198198

199-
if (platform !== "win32") {
200-
const stat = yield* fileSystem.stat(candidate).pipe(Effect.option);
201-
if (Option.isSome(stat) && (stat.value.mode & 0o111) === 0) {
199+
const stat = yield* fileSystem.stat(candidate).pipe(Effect.option);
200+
if (Option.isSome(stat)) {
201+
// Directories are executable-looking on win32, where the exec-bit test
202+
// below is skipped, and only fail later at spawn.
203+
const unusable =
204+
stat.value.type === "Directory" ||
205+
(platform !== "win32" && (stat.value.mode & 0o111) === 0);
206+
if (unusable) {
202207
return yield* new ResourceMonitorBinaryNotExecutable({
203208
path: candidate,
204209
mode: stat.value.mode,

0 commit comments

Comments
 (0)