@andersbakken/fisk 5.0.3 → 5.0.4

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.
@@ -3434,26 +3434,38 @@ var output = {
3434
3434
  var fs = libExports;
3435
3435
 
3436
3436
  // systemd socket activation: the first passed fd is at SD_LISTEN_FDS_START (3).
3437
- // See sd_listen_fds(3). When LISTEN_PID matches our pid and LISTEN_FDS >= 1,
3438
- // listen on the inherited fd instead of creating a new socket. This lets
3439
- // systemd own the socket file, so its inode survives daemon restarts and any
3440
- // bind-mount of the socket (e.g. docker -v /tmp/fisk.socket:/tmp/fisk.socket)
3441
- // keeps working across upgrades.
3437
+ // See sd_listen_fds(3). systemd sets LISTEN_PID to the PID it should be
3438
+ // consumed by; a child process must be exec'd (not fork+exec of a wrapper)
3439
+ // so its own pid matches. We fail hard on any mismatch rather than silently
3440
+ // falling back to path binding, because that fallback would unlink the
3441
+ // systemd-owned socket file and re-create a new inode, defeating the whole
3442
+ // point of activation (and breaking every docker container that bind-mounted
3443
+ // the socket file).
3442
3444
  const SD_LISTEN_FDS_START = 3;
3443
3445
  function systemdListenFd() {
3444
- const pid = process.env.LISTEN_PID;
3445
- const fds = process.env.LISTEN_FDS;
3446
- if (!pid || !fds) {
3447
- return undefined;
3448
- }
3449
- if (parseInt(pid, 10) !== process.pid) {
3450
- return undefined;
3451
- }
3452
- const count = parseInt(fds, 10);
3453
- if (!count || count < 1) {
3454
- return undefined;
3455
- }
3456
- return SD_LISTEN_FDS_START;
3446
+ const pidRaw = process.env.LISTEN_PID;
3447
+ const fdsRaw = process.env.LISTEN_FDS;
3448
+ // Consume the activation env so any subprocess we spawn does not inherit
3449
+ // stale LISTEN_PID/LISTEN_FDS. sd_listen_fds_with_names(3) recommends
3450
+ // unsetenv after use.
3451
+ delete process.env.LISTEN_PID;
3452
+ delete process.env.LISTEN_FDS;
3453
+ delete process.env.LISTEN_FDNAMES;
3454
+ if (!pidRaw && !fdsRaw) {
3455
+ return "none";
3456
+ }
3457
+ if (!pidRaw || !fdsRaw) {
3458
+ return "mismatch";
3459
+ }
3460
+ const pid = Number(pidRaw);
3461
+ const count = Number(fdsRaw);
3462
+ if (!Number.isInteger(pid) || !Number.isInteger(count) || count < 1) {
3463
+ return "mismatch";
3464
+ }
3465
+ if (pid !== process.pid) {
3466
+ return "mismatch";
3467
+ }
3468
+ return { fd: SD_LISTEN_FDS_START };
3457
3469
  }
3458
3470
  class Server extends EventEmitter__default["default"] {
3459
3471
  constructor(option, common) {
@@ -3486,8 +3498,13 @@ class Server extends EventEmitter__default["default"] {
3486
3498
  }
3487
3499
  }
3488
3500
  listen() {
3489
- const inheritedFd = systemdListenFd();
3490
- if (inheritedFd !== undefined) {
3501
+ const activation = systemdListenFd();
3502
+ if (activation === "mismatch") {
3503
+ console.error("fisk-daemon: LISTEN_FDS/LISTEN_PID present but do not match our pid. Refusing to fall back to path binding -- exiting so systemd can restart us with correct activation.");
3504
+ process.exit(1);
3505
+ }
3506
+ if (activation !== "none") {
3507
+ const inheritedFd = activation.fd;
3491
3508
  this._activated = true;
3492
3509
  if (this.debug) {
3493
3510
  console.log("Server::listen using systemd-activated fd", inheritedFd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andersbakken/fisk",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "Fisk, a distributed compile system",
5
5
  "scripts": {
6
6
  "lint": "eslint . --ext .ts",