| … | … | @@ -7,6 +7,12 @@ import crypto from 'hypercore-crypto' |
| 7 | 7 | import b4a from 'b4a' |
| 8 | 8 | import fs from 'bare-fs' |
| 9 | 9 | import process from 'bare-process' // for the OTA respawn exit — Bare has no global process |
| 10 | |
| 11 | // Set by the daemon entrypoint, which owns close() and therefore the exit. Kept module-level rather than |
| 12 | // threaded through bootMultiDevice -> bootSwarmDevice because the UDS surface is created deep inside the |
| 13 | // per-device boot and the only thing it needs is "tell whoever owns the process". |
| 14 | let otaHandler = null |
| 15 | export function setOtaHandler (fn) { otaHandler = typeof fn === 'function' ? fn : null } |
| 10 | 16 | import Hyperswarm from 'hyperswarm' |
| 11 | 17 | import ProtomuxWakeup from 'protomux-wakeup' |
| 12 | 18 | import Protomux from 'protomux' |
| … | … | @@ -495,12 +501,15 @@ export async function bootSwarmDevice ({ storage, deviceMnemonic, did, signingKe |
| 495 | 501 | // stall on an un-converged base's base.update), so a co-located client (favela-web) can ALWAYS reach the |
| 496 | 502 | // device over local IPC even while convergence lags. Owner-gated by the filesystem → no writer-allowlist. |
| 497 | 503 | try { |
| 498 | | // OTA respawn: a clean close, then exit 75 for the supervisor. Exiting the PROCESS is the daemon's |
| 499 | | // call, not the UDS module's, so it is injected here. |
| 504 | // OTA respawn. This used to call `this.close()` — but this is inside bootSwarmDevice, a plain |
| 505 | // FUNCTION, so in an ES module `this` is undefined and it threw a TypeError that serve-device-uds's |
| 506 | // try/catch swallowed: the handler logged "respawning" and then silently did nothing, which is |
| 507 | // exactly how it shipped in 0.3.100-0.3.103. The process lifecycle belongs to index.js (it owns |
| 508 | // `daemon` and its close), so it registers the handler and this only signals. |
| 500 | 509 | udsServing = await serveDeviceUds(device, { |
| 501 | 510 | uds: join(ctlDir, 'control.sock'), |
| 502 | 511 | blobs, |
| 503 | | onRelease: () => { Promise.resolve(this.close()).catch(() => {}).then(() => process.exit(75)).catch(() => process.exit(75)) } |
| 512 | onRelease: () => { if (otaHandler) otaHandler() } |
| 504 | 513 | }) |
| 505 | 514 | console.log(JSON.stringify({ msg: 'device UDS control surface', uds: join(ctlDir, 'control.sock') })) |
| 506 | 515 | } catch (e) { console.error(JSON.stringify({ msg: 'UDS control surface failed (swarm surface still up)', error: e.message })) } |