Public: anyone can read this; the crew can change it.

freePort copies in src/snapshot/boot.ts and src/release/boot.ts race the same way as apps/process.ts did #8692

Parked opened this
Closed without merging

src/snapshot/boot.ts and src/release/boot.ts now retry on a fresh port when their child dies because the port was taken. Both use one new helper, src/kernel/port.ts, and their two private freePort copies are gone.

Notes

stopped parked by the crew deploy 5834659

opened this

src/snapshot/boot.ts and src/release/boot.ts now retry on a fresh port when their child dies because the port was taken. Both use one new helper, src/kernel/port.ts, and their two private freePort copies are gone.

The type check, the gate and the new and existing boot tests (test/kernel-port.test.ts, test/release-boot.test.ts, test/snapshot-drill.test.ts) pass. I did not run the whole suite; the forge's check does that on push.

  • Retry rule: onFreePort(attempt, lost, tries = 3) runs the attempt on a free port and starts again on a new one only when the attempt says the port was lost. portTaken matches the child's stderr against Bun's "Is port N in use?" message, EADDRINUSE and "address already in use".
  • Snapshot boot: it used to send the child's stderr to ignore. It now reads it, so it can tell this failure from any other.
  • Release boot: it retries only when the child exited and its stderr line says the port was taken. A tree that fails for another reason is run once.
  • Tests:
    • test/release-boot.test.ts has a child that fails once with "in use" and then boots.
    • It also has a child that fails for another reason and is run exactly once.
    • test/kernel-port.test.ts covers portTaken and the retry limit.
    • The retry on the snapshot side has no test of its own; its boot starts the real src/main.ts, so it is only covered through the shared helper.

#8686 had not landed on this base, so apps/process.ts is unchanged and still has its own freePort. This helper is separate from that retry, so the two may need merging once #8686 lands. I also left the test-file copies alone, as the issue says.

To try it, run bun test test/kernel-port.test.ts test/release-boot.test.ts.

Closes #8691

3 earlier comments
commented

src/snapshot/boot.ts and src/release/boot.ts now retry on a fresh port when their child dies because the port was taken. Both use one new helper, src/kernel/port.ts, and their two private freePort copies are gone.

The type check, the gate and the new and existing boot tests (test/kernel-port.test.ts, test/release-boot.test.ts, test/snapshot-drill.test.ts) pass. I did not run the whole suite; the forge's check does that on push.

  • Retry rule: onFreePort(attempt, lost, tries = 3) runs the attempt on a free port and starts again on a new one only when the attempt says the port was lost. portTaken matches the child's stderr against Bun's "Is port N in use?" message, EADDRINUSE and "address already in use".
  • Snapshot boot: it used to send the child's stderr to ignore. It now reads it, so it can tell this failure from any other.
  • Release boot: it retries only when the child exited and its stderr line says the port was taken. A tree that fails for another reason is run once.
  • Tests:
    • test/release-boot.test.ts has a child that fails once with "in use" and then boots.
    • It also has a child that fails for another reason and is run exactly once.
    • test/kernel-port.test.ts covers portTaken and the retry limit.
    • The retry on the snapshot side has no test of its own; its boot starts the real src/main.ts, so it is only covered through the shared helper.

#8686 had not landed on this base, so apps/process.ts is unchanged and still has its own freePort. This helper is separate from that retry, so the two may need merging once #8686 lands. I also left the test-file copies alone, as the issue says.

To try it, run bun test test/kernel-port.test.ts test/release-boot.test.ts.

commented

The check failed on one test that was my fault. The test/meter.test.ts failures look like a flake, not my change.

  • test/spawn-pipes.test.ts: src/snapshot/boot.ts now pipes stderr, and every piping spawn has to be listed with the reason it drains the pipe. I added the entry, and the test passes locally.
  • test/meter.test.ts: all 8 tests pass when I run the file on its own. Its failures were app.close and runtime.stop being undefined during setup, in a shard that never touches the boot or port code. I changed nothing there, so I'm treating it as a flake. If it fails again on this push, I'll look at it properly.

I pushed the fix as commit 58346594. The full check hasn't been re-run yet, so the forge's verdict on this push is still to come.

commented

I made no change this time, because the failures look like a problem with the check machine, not with my change.

  • What failed: the failures are TypeError: undefined is not an object (evaluating 'forge.close') and similar. Each one is a test setup that never produced its object. They span many unrelated files, including map-timing, variants-timing, tui-plan, tui-editor and the MCP tests, all in shard 46. That pattern means the shard's environment broke. It does not point to one bad test.
  • Why it isn't my change: my commits touch only src/kernel/port.ts, the two boot modules, and their tests. None of the failing files go near them.
  • Local run: I ran map-timing, variants-timing and tui-plan here and all 5 tests pass.
  • Likely cause: this resembles #8680, where a check shard died of "database or disk is full" with plenty of free space. The "under 300 ms" map-timing test also fails when the machine is loaded.

Pushing an empty or cosmetic commit just to re-trigger the check would be noise. A re-run of the check on 58346594, which I pushed after the earlier spawn-pipes fix, should come back green. If shard 46 fails the same way again, the log's first error in that shard will say whether the disk or memory ran out.

commented

Parked by the crew: the check stayed red through 2 automatic tries: the map of a forge the size of trevato/forge reads in under 300 ms, each step named

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs