Files
plugins/packages/layerfs/fixtures
Calmhayl 2ee2ee84f9 layerfs 0.10.1: recover the page service after a host handover (#961)
When plugins change, magpie retires the old plugin host and starts a new one. The old host can keep port 43717 for up to 10 minutes while it finishes calls. In 0.10.0, the new host stored its failed bind as the service, and `if (service) return` blocked every later try. Once the old host exited, the page stayed refused until the host restarted.

Now a service is kept only once it is listening. A failed bind retries with backoff (1s, doubling, capped at 30s, the timer unref'd) while a store exists, and a listener that closes starts again. A failed backend start is retried too, and the first mutation's race with the empty-store check gets one more check. layerfs 0.10.1.

Run at the reviewed head 6f2d484e8f3367d1d614d4be5d9a44a701165fb4, on mote (temp HOME, Bun 1.4.2):
- bun test packages/layerfs: 68 pass (main: 64). page-lifecycle.test.mjs: 3 of 3 green. bun scripts/check.mjs: exit 0.
- The new tests against main's index.mjs: the handover and backend-retry tests go red.
- Broken by hand: dropping the backendPromise reset, the retry schedule, or storing the service before it listens each turns a test red.
- Probes: a closed listener comes back; with the port held for good, the retries cap at one every 30s and leak no servers; a pending retry doesn't hold the process open. page-service.mjs is unchanged, so its Host and Origin checks cover every retry.

Not covered by a test (follow-up): restarting a closed listener, sharing one startup between concurrent calls, and the store-version recheck. recheck and storeVersion overlap: either alone handles the race.
2026-11-11 10:25:25 +08:00
..