@decentnetwork/lan 0.1.188 → 0.1.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
Binary file
@@ -664,43 +664,51 @@ export class DaemonServer {
664
664
  selfRestart: async () => {
665
665
  // Detach a child process that waits briefly and then re-execs
666
666
  // the same argv we were started with. Inherits privileges
667
- // (root daemon → root child, no sudo prompt). The current
668
- // process exits cleanly after responding to the IPC call so
669
- // the child can rebind the TUN. The brief sleep gives the
670
- // current process time to flush its IPC response, close
671
- // sockets, and release the pidfile/TUN before the new
672
- // process tries to claim them.
667
+ // (root daemon → root child, no sudo prompt).
668
+ //
669
+ // IMPORTANT: run the normal graceful shutdown before spawning
670
+ // the replacement. Peer.stop() notifies established friends that
671
+ // this net_crypto session is going away; skipping it strands the
672
+ // remote side on our old ephemeral session key. Presence then
673
+ // remains online while chat/TUN packets from the restarted process
674
+ // are rejected until the remote daemon is restarted too.
673
675
  const { spawn } = await import("child_process");
674
676
  const argv = process.argv.slice();
675
677
  const node = argv.shift();
676
678
  this.logger.info(`Self-restart requested via IPC — relaunching ${node} ${argv.join(" ")}`);
677
679
  // Schedule shutdown for after the IPC response goes out. The
678
- // 50ms timeout is plenty for the response to leave; the
679
- // child's own 1s sleep below is the real arbiter.
680
+ // 50ms timeout lets the response leave before cleanup closes IPC.
680
681
  setTimeout(() => {
681
- try {
682
- // sh -c so we can shell-quote argv safely and use sleep.
683
- // The trailing `&` puts the relauncher into the
684
- // background of sh — sh then exits — and Node's detached
685
- // flag reparents the relauncher to PID 1. Result: a
686
- // fully detached new daemon that inherits our uid/gid.
687
- const cmd = `sleep 1 && exec ${shellQuote([node, ...argv])}`;
688
- const child = spawn("sh", ["-c", cmd], {
689
- detached: true,
690
- stdio: "ignore",
691
- env: process.env,
692
- });
693
- child.unref();
694
- }
695
- catch (err) {
696
- this.logger.error(`Self-restart spawn failed: ${err instanceof Error ? err.message : err}`);
697
- }
698
- // Give the child its 1s head-start, then exit so the
699
- // pidfile and TUN are released before the relauncher tries
700
- // to grab them.
701
- setTimeout(() => process.exit(0), 200);
682
+ void (async () => {
683
+ try {
684
+ await this.stop();
685
+ }
686
+ catch (err) {
687
+ // cleanup() is already best-effort component by component,
688
+ // but do not make an upgrade impossible if an unexpected
689
+ // shutdown error escapes it.
690
+ this.logger.error(`Self-restart cleanup failed: ${err instanceof Error ? err.message : err}`);
691
+ }
692
+ try {
693
+ // sh -c so we can shell-quote argv safely and use sleep.
694
+ // Node's detached flag reparents the relauncher to PID 1.
695
+ // At this point stop() has released IPC, TUN and the pidfile;
696
+ // the extra delay also lets relay writes flush remotely.
697
+ const cmd = `sleep 1 && exec ${shellQuote([node, ...argv])}`;
698
+ const child = spawn("sh", ["-c", cmd], {
699
+ detached: true,
700
+ stdio: "ignore",
701
+ env: process.env,
702
+ });
703
+ child.unref();
704
+ }
705
+ catch (err) {
706
+ this.logger.error(`Self-restart spawn failed: ${err instanceof Error ? err.message : err}`);
707
+ }
708
+ setTimeout(() => process.exit(0), 200);
709
+ })();
702
710
  }, 50);
703
- return { scheduledMs: 250, argv: [node, ...argv] };
711
+ return { scheduledMs: 1500, argv: [node, ...argv] };
704
712
  },
705
713
  diag: async () => {
706
714
  // Snapshot of everything an operator needs to debug why
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/lan",
3
- "version": "0.1.188",
3
+ "version": "0.1.189",
4
4
  "description": "Private virtual LAN for self-hosted services and AI agents, built on Elastos Carrier. NAT-traversal, name service, ACL, all over a peer-to-peer mesh — no public IP required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@decentnetwork/dora": "^0.1.13",
82
- "@decentnetwork/peer": "^0.1.92",
82
+ "@decentnetwork/peer": "^0.1.93",
83
83
  "@decentnetwork/peer-webrtc": "^0.2.10",
84
84
  "ink": "^5.2.1",
85
85
  "js-yaml": "^4.1.0",