Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a child killed with unread input no longer crashes the server on html_render #16555

Closedwfclark5(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/16555/headopened View on GitHub

Showing 4 changed files with 125 additions and 0 deletions.

x
0 of 4 viewed, 4 left
53 additions and 0 deletionsapps/server/src/process/spawnerPipeErrors.test.tsAdded
View file
@@ -0,0 +1,53 @@
+import { describe, it } from "@effect/vitest";
+import * as NodeServices from "@effect/platform-node/NodeServices";
+import * as Deferred from "effect/Deferred";
+import * as Effect from "effect/Effect";
+import * as Stream from "effect/Stream";
+import * as ChildProcess from "effect/process/ChildProcess";
+import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
+import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
+​
+// Covers patches/@effect__platform-node-shared@4.0.1.patch. A stopped child
+// never reads its input, so a chunk larger than the socket buffer leaves a
+// write queued. Closing the scope interrupts the writer and kills the child,
+// and the pipe then fails with EPIPE (stdin) or ECONNRESET (extra fds, which
+// Node also reads). Unpatched, nothing listens by then and the uncaught error
+// kills the server, as HtmlRender's Chrome pipe did on every torn-down capture.
+const killChildWithQueuedInput = (target: "stdin" | "fd3") =>
+ Effect.gen(function* () {
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
+ yield* Effect.scoped(
+ Effect.gen(function* () {
+ const child = yield* spawner.spawn(
+ ChildProcess.make(process.execPath, ["-e", "process.kill(process.pid, 'SIGSTOP')"], {
+ stdin: "pipe",
+ stdout: "ignore",
+ stderr: "ignore",
+ forceKillAfter: "100 millis",
+ additionalFds: { fd3: { type: "input" } },
+ }),
+ );
+ const pulled = yield* Deferred.make<void>();