@andersbakken/fisk 5.0.1 → 5.0.3

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.
@@ -27,31 +27,36 @@ var os__default = /*#__PURE__*/_interopDefaultLegacy(os$1);
27
27
  var net__default = /*#__PURE__*/_interopDefaultLegacy(net);
28
28
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
29
29
 
30
- /*! *****************************************************************************
31
- Copyright (c) Microsoft Corporation.
32
-
33
- Permission to use, copy, modify, and/or distribute this software for any
34
- purpose with or without fee is hereby granted.
35
-
36
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
37
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
39
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
40
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
41
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
42
- PERFORMANCE OF THIS SOFTWARE.
43
- ***************************************************************************** */
44
-
45
- function __awaiter(thisArg, _arguments, P, generator) {
46
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
- return new (P || (P = Promise))(function (resolve, reject) {
48
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
49
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
50
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
51
- step((generator = generator.apply(thisArg, _arguments || [])).next());
52
- });
30
+ /******************************************************************************
31
+ Copyright (c) Microsoft Corporation.
32
+
33
+ Permission to use, copy, modify, and/or distribute this software for any
34
+ purpose with or without fee is hereby granted.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
37
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
39
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
40
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
41
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
42
+ PERFORMANCE OF THIS SOFTWARE.
43
+ ***************************************************************************** */
44
+
45
+ function __awaiter(thisArg, _arguments, P, generator) {
46
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
+ return new (P || (P = Promise))(function (resolve, reject) {
48
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
49
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
50
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
51
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
52
+ });
53
53
  }
54
54
 
55
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
56
+ var e = new Error(message);
57
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
58
+ };
59
+
55
60
  const execFileAsync = require$$4.promisify(child_process.execFile);
56
61
  // Prefixes removed from a compiler's `-v` output before hashing / parsing.
57
62
  // Must match filter() in src/client/Client.cpp (lines 234-257).
@@ -3428,6 +3433,28 @@ var output = {
3428
3433
 
3429
3434
  var fs = libExports;
3430
3435
 
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.
3442
+ const SD_LISTEN_FDS_START = 3;
3443
+ 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;
3457
+ }
3431
3458
  class Server extends EventEmitter__default["default"] {
3432
3459
  constructor(option, common) {
3433
3460
  super();
@@ -3438,6 +3465,7 @@ class Server extends EventEmitter__default["default"] {
3438
3465
  this.option = option;
3439
3466
  this._connections = {};
3440
3467
  this._connectionId = 0;
3468
+ this._activated = false;
3441
3469
  }
3442
3470
  close() {
3443
3471
  if (this.debug) {
@@ -3446,14 +3474,44 @@ class Server extends EventEmitter__default["default"] {
3446
3474
  if (this.server) {
3447
3475
  this.server.close();
3448
3476
  }
3449
- try {
3450
- fs.unlinkSync(this.file);
3451
- }
3452
- catch (err) {
3453
- /* */
3477
+ // When socket-activated, systemd owns the socket file. Do not unlink
3478
+ // it -- that would break the bind-mount contract for existing clients.
3479
+ if (!this._activated) {
3480
+ try {
3481
+ fs.unlinkSync(this.file);
3482
+ }
3483
+ catch (err) {
3484
+ /* */
3485
+ }
3454
3486
  }
3455
3487
  }
3456
3488
  listen() {
3489
+ const inheritedFd = systemdListenFd();
3490
+ if (inheritedFd !== undefined) {
3491
+ this._activated = true;
3492
+ if (this.debug) {
3493
+ console.log("Server::listen using systemd-activated fd", inheritedFd);
3494
+ }
3495
+ return new Promise((resolve) => {
3496
+ let connected = false;
3497
+ this.server = net__default["default"].createServer(this._onConnection.bind(this));
3498
+ this.server.listen({ fd: inheritedFd }, () => {
3499
+ connected = true;
3500
+ resolve();
3501
+ });
3502
+ this.server.on("error", (err) => {
3503
+ if (!connected) {
3504
+ console.error("Got server error", err);
3505
+ setTimeout(this.listen.bind(this), 1000);
3506
+ }
3507
+ });
3508
+ this.server.on("close", () => {
3509
+ if (!connected) {
3510
+ setTimeout(this.listen.bind(this), 1000);
3511
+ }
3512
+ });
3513
+ });
3514
+ }
3457
3515
  try {
3458
3516
  fs.unlinkSync(this.file); // this should be more
3459
3517
  // complicated with attempts to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andersbakken/fisk",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Fisk, a distributed compile system",
5
5
  "scripts": {
6
6
  "lint": "eslint . --ext .ts",
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@andersbakken/blessed": "^0.1.82",
36
- "@andersbakken/fisk-native": "^24.0.0",
36
+ "@andersbakken/fisk-native": "^25.0.0",
37
37
  "@jhanssen/options": "^10.0.0",
38
38
  "axios": "^0.21.1",
39
39
  "bufferutil": "^4.0.7",