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 #8769

opened this

Merged 32d 4h ago, live in production

The snapshot and release boots now start their child again on a fresh port when it dies because another process took the port first. bun scripts/gate.ts and bun x tsc --noEmit came back clean. test/kernel-port.test.ts, test/release-boot.test.ts and test/drill-verdict.test.ts pass (22 tests).

Notes

opened this

The snapshot and release boots now start their child again on a fresh port when it dies because another process took the port first. bun scripts/gate.ts and bun x tsc --noEmit came back clean. test/kernel-port.test.ts, test/release-boot.test.ts and test/drill-verdict.test.ts pass (22 tests). I did not run the full suite, and no test provokes a real collision in either boot, since that race is hard to stage.

What moved

  • New shared module: src/kernel/port.ts holds freePort(), lostPort(output) and onFreshPort(attempt). It imports nothing, so release/boot.ts still runs when the rest of the tree is broken.
  • onFreshPort: it runs an attempt on a free port and, while the attempt reports the port lost, retries on a fresh one. It makes at most 2 retries, the same budget as apps/process.ts from #8686.
  • src/release/boot.ts: bootProof now calls onFreshPort. The port counts as lost when the child exits and its stderr matches the address-in-use pattern.
  • src/snapshot/boot.ts: bootRestored does the same. It used to discard the child's stderr, so it now pipes and reads it to see why the child died. The failure messages read as before.
  • Test: test/kernel-port.test.ts covers the retry count and the address-in-use pattern.

Not done

  • I left freePort and the retry loop in apps/process.ts alone, because #8686 settled it and spawn/cell.ts imports it. Moving it onto the shared module would be a follow-up.
  • The test-file copies are untouched, as the issue says.

To try it: run bun src/release/boot.ts. It boots the tree on a scratch data directory and prints one line.

Closes #8691

2 earlier comments
commented

The snapshot and release boots now start their child again on a fresh port when it dies because another process took the port first. bun scripts/gate.ts and bun x tsc --noEmit came back clean. test/kernel-port.test.ts, test/release-boot.test.ts and test/drill-verdict.test.ts pass (22 tests). I did not run the full suite, and no test provokes a real collision in either boot, since that race is hard to stage.

What moved

  • New shared module: src/kernel/port.ts holds freePort(), lostPort(output) and onFreshPort(attempt). It imports nothing, so release/boot.ts still runs when the rest of the tree is broken.
  • onFreshPort: it runs an attempt on a free port and, while the attempt reports the port lost, retries on a fresh one. It makes at most 2 retries, the same budget as apps/process.ts from #8686.
  • src/release/boot.ts: bootProof now calls onFreshPort. The port counts as lost when the child exits and its stderr matches the address-in-use pattern.
  • src/snapshot/boot.ts: bootRestored does the same. It used to discard the child's stderr, so it now pipes and reads it to see why the child died. The failure messages read as before.
  • Test: test/kernel-port.test.ts covers the retry count and the address-in-use pattern.

Not done

  • I left freePort and the retry loop in apps/process.ts alone, because #8686 settled it and spawn/cell.ts imports it. Moving it onto the shared module would be a follow-up.
  • The test-file copies are untouched, as the issue says.

To try it: run bun src/release/boot.ts. It boots the tree on a scratch data directory and prints one line.

commented

One of the two failing tests is fixed and pushed. The other one I could not reproduce, so I left it alone.

  • every spawn that pipes is listed…: this was my doing. src/snapshot/boot.ts now pipes stderr, and that test keeps a register of every spawn that does. I added an entry for the file in test/spawn-pipes.test.ts, and the test passes locally.
  • a row wears a dot, not a word badge…: it lives in test/studio-words.test.ts, and it passes locally. My change doesn't touch the studio pages or anything they import. The check log says it was not re-run alone, so I can't tell whether it failed for a real reason or under load. If it fails again on this push, I'll look at it properly.

The fix is commit a671387e. I ran only those two test files here, not the full suite.

commented

Both boots are now tested for the retry wiring, and I've pushed it as d895c847. The type check, the gate, test/kernel-port.test.ts, test/release-boot.test.ts and test/spawn-pipes.test.ts all pass locally. I did not run the full suite.

  • bootProof: a tree whose src/main.ts logs a run, prints error: address already in use and exits 1 is run PORT_RETRIES + 1 times and returns ok:false. A tree that exits with TypeError: x is run once, so a non-port failure is not retried.
  • bootRestored: it now takes an optional third argument, tree, which defaults to the repository tree. The two cases above run through it as well. Without this argument there was no way to inject a tree, so the change adds no behaviour of its own.
  • freePort: a new test checks that it returns a port from 1 to 65535.

I agreed with every point in the review and have nothing to push back on.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs