kuzzle 2.61.0 → 2.61.1-beta.2

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.
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ClusterIdCardHandler = exports.IdCard = void 0;
27
27
  exports.idCardTtl = idCardTtl;
28
28
  exports.getIdCards = getIdCards;
29
+ const async_1 = require("../util/async");
29
30
  const name_generator_1 = require("../util/name-generator");
30
31
  const node_child_process_1 = require("node:child_process");
31
32
  const node_path_1 = require("node:path");
@@ -316,10 +317,16 @@ class ClusterIdCardHandler {
316
317
  // The worker deletes the card too, but nothing waits for it: the process
317
318
  // usually exits first, and the card then outlives it by a TTL, long
318
319
  // enough for a node restarted on this IP to take it for a live duplicate
320
+ //
321
+ // Bounded like each renewal (#3181): this runs on the shutdown that a
322
+ // failed renewal starts, and the redis that made it fail is likely mute
319
323
  if (this.nodeIdKey !== null) {
324
+ const nodeIdKey = this.nodeIdKey;
320
325
  try {
321
- await global.kuzzle.ask("core:cache:internal:del", this.nodeIdKey);
322
- await global.kuzzle.ask("core:cache:internal:execute", "srem", REDIS_ID_CARDS_INDEX, this.nodeIdKey);
326
+ await (0, async_1.withTimeout)((async () => {
327
+ await global.kuzzle.ask("core:cache:internal:del", nodeIdKey);
328
+ await global.kuzzle.ask("core:cache:internal:execute", "srem", REDIS_ID_CARDS_INDEX, nodeIdKey);
329
+ })(), this.refreshDelay);
323
330
  }
324
331
  catch (error) {
325
332
  this.logger.warn(`Could not delete the ID card ${this.nodeIdKey}: it expires in ${this.ttl}ms (${error instanceof Error ? error.message : String(error)})`);
@@ -364,7 +364,7 @@ class ClusterPublisher {
364
364
  // (don't), then you have to first make a local copy of this.lastMessageId
365
365
  // to make sure that the value returned to the caller has not been
366
366
  // increased by other calls
367
- this.bufferSend(topic, buffer);
367
+ void this.bufferSend(topic, buffer);
368
368
  return this.lastMessageId;
369
369
  }
370
370
  /**
@@ -35,6 +35,13 @@ declare class IDCardRenewer {
35
35
  refreshMultiplier: number;
36
36
  /** Disposed until `init()` says otherwise. */
37
37
  disposed: boolean;
38
+ /**
39
+ * How long a single redis command may take, in ms. Renewals are spaced by
40
+ * `refreshDelay`: one still pending when the next is due is already late,
41
+ * and since the card outlives its last renewal by `refreshMultiplier` (≥ 2)
42
+ * delays, giving up then reports the failure no later than the card expires.
43
+ */
44
+ get commandTimeout(): number;
38
45
  init(config: IDCardRenewerConfig): Promise<void>;
39
46
  initRedis(config?: RedisServiceConfig, name?: string): Promise<void>;
40
47
  renewIDCard(): Promise<void>;
@@ -10,6 +10,7 @@ const node_util_1 = require("node:util");
10
10
  // reaching this module dies on "Cannot find module". It type-checks against
11
11
  // `export =` under `esModuleInterop`. See ADR-0001, TD-49 (#2739).
12
12
  const redis_1 = __importDefault(require("../../service/cache/redis"));
13
+ const async_1 = require("../../util/async");
13
14
  /**
14
15
  * What `idCardHandler.createIdCard()` sends this worker with `action: "start"`.
15
16
  * It is a `child_process.fork()` child, so everything here crossed an IPC
@@ -33,6 +34,15 @@ class IDCardRenewer {
33
34
  /** Disposed until `init()` says otherwise. */
34
35
  this.disposed = true;
35
36
  }
37
+ /**
38
+ * How long a single redis command may take, in ms. Renewals are spaced by
39
+ * `refreshDelay`: one still pending when the next is due is already late,
40
+ * and since the card outlives its last renewal by `refreshMultiplier` (≥ 2)
41
+ * delays, giving up then reports the failure no later than the card expires.
42
+ */
43
+ get commandTimeout() {
44
+ return this.refreshDelay;
45
+ }
36
46
  async init(config) {
37
47
  if (!this.disposed) {
38
48
  return; // Already initialized
@@ -100,7 +110,10 @@ class IDCardRenewer {
100
110
  return;
101
111
  }
102
112
  try {
103
- const refreshed = await this.redis.commands.pexpire(this.nodeIdKey, this.refreshDelay * this.refreshMultiplier);
113
+ // Bounded (#3181): a redis that stops answering without closing the
114
+ // socket leaves the command queued until the OS gives up on the TCP
115
+ // connection, about 10 minutes, while the card expires within seconds.
116
+ const refreshed = await (0, async_1.withTimeout)(this.redis.commands.pexpire(this.nodeIdKey, this.refreshDelay * this.refreshMultiplier), this.commandTimeout);
104
117
  // Unable to refresh the key in time before it expires
105
118
  // => this node is too slow, we need to remove it from the cluster
106
119
  if (refreshed === 0) {
@@ -136,7 +149,9 @@ class IDCardRenewer {
136
149
  return;
137
150
  }
138
151
  try {
139
- await this.redis.commands.del(this.nodeIdKey);
152
+ // Bounded too: a failed renewal is reported to the parent only once
153
+ // this returns, and the redis that made it fail is likely still mute.
154
+ await (0, async_1.withTimeout)(this.redis.commands.del(this.nodeIdKey), this.commandTimeout);
140
155
  }
141
156
  catch (error) {
142
157
  // eslint-disable-next-line no-console
@@ -156,7 +156,8 @@ class Router {
156
156
  if (message.method === "OPTIONS") {
157
157
  request.input.headers = message.headers;
158
158
  request.response.configure({ result: {}, status: 200 });
159
- global.kuzzle.pipe("http:options", request, (error, result) => {
159
+ // With a callback, `pipe` answers through it and returns no promise
160
+ void global.kuzzle.pipe("http:options", request, (error, result) => {
160
161
  if (error) {
161
162
  replyWithError(cb, request, error);
162
163
  }
@@ -84,6 +84,7 @@ const statistics_1 = __importDefault(require("../core/statistics/statistics"));
84
84
  const storageEngine_1 = __importDefault(require("../core/storage/storageEngine"));
85
85
  const validation_1 = __importDefault(require("../core/validation/validation"));
86
86
  const kerror = __importStar(require("../kerror"));
87
+ const async_1 = require("../util/async");
87
88
  const asyncStore_1 = __importDefault(require("../util/asyncStore"));
88
89
  const crypto_1 = require("../util/crypto");
89
90
  const distributedLock_1 = require("../util/distributedLock");
@@ -108,6 +109,10 @@ const FAILURE_SHUTDOWN_TIMEOUT = 30000;
108
109
  * them on shutdown, so the wait is bounded (#3160)
109
110
  */
110
111
  const PLUGIN_REQUESTS_SHUTDOWN_TIMEOUT = 5000;
112
+ /**
113
+ * How long a shutdown tries to give its locks back to redis, in ms
114
+ */
115
+ const LOCKS_RELEASE_SHUTDOWN_TIMEOUT = 2000;
111
116
  /**
112
117
  * Stops the startup sequence once a shutdown has begun (#3045): `start()`
113
118
  * catches it and leaves the shutdown to end the process. Internal: never
@@ -372,11 +377,18 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
372
377
  this.log.warn(`[shutdown] ${this.funnel.pluginRequests} plugin requests still running after ${PLUGIN_REQUESTS_SHUTDOWN_TIMEOUT}ms: closing the storage anyway`);
373
378
  }
374
379
  // The other nodes may be waiting on a lock this one holds: a node leaving
375
- // mid-startup is often in the middle of one (F-13).
376
- await Promise.all([
377
- (0, distributedLock_1.releaseAllLocksBeforeExit)(),
378
- mutex_1.Mutex.releaseAllBeforeExit(), // NOSONAR: frees locks taken through the deprecated API
379
- ]);
380
+ // mid-startup is often in the middle of one (F-13). Bounded: a node often
381
+ // leaves because redis stopped answering, and a lock that cannot be freed
382
+ // still expires with its TTL (#3181)
383
+ try {
384
+ await (0, async_1.withTimeout)(Promise.all([
385
+ (0, distributedLock_1.releaseAllLocksBeforeExit)(),
386
+ mutex_1.Mutex.releaseAllBeforeExit(), // NOSONAR: frees locks taken through the deprecated API
387
+ ]), LOCKS_RELEASE_SHUTDOWN_TIMEOUT);
388
+ }
389
+ catch {
390
+ this.log.warn(`[shutdown] Locks still held after ${LOCKS_RELEASE_SHUTDOWN_TIMEOUT}ms: they expire with their TTL`);
391
+ }
380
392
  // Nothing reads or writes the storage anymore: its drivers may release
381
393
  // their connections (bounded, never rejects)
382
394
  await this.storageEngine?.close();
@@ -10,6 +10,8 @@ interface RedisInfo {
10
10
  memoryPeak: string;
11
11
  memoryUsed: string;
12
12
  mode: string;
13
+ /** The server answering, from its own report: Redis, or a fork of it */
14
+ server: "redis" | "valkey";
13
15
  type: "redis";
14
16
  version: string;
15
17
  }
@@ -246,12 +246,17 @@ class Redis extends service_1.default {
246
246
  }
247
247
  }
248
248
  }
249
+ // Valkey reports `redis_version:7.2.4` whatever its own version, for the
250
+ // clients that check it: its version is `valkey_version`. Valkey 9 also
251
+ // renamed `redis_mode` to `server_mode`.
252
+ const isValkey = info.server_name === "valkey";
249
253
  return {
250
254
  memoryPeak: info.used_memory_peak_human ?? "",
251
255
  memoryUsed: info.used_memory_human ?? "",
252
- mode: info.redis_mode ?? "",
256
+ mode: info.redis_mode ?? info.server_mode ?? "",
257
+ server: isValkey ? "valkey" : "redis",
253
258
  type: "redis",
254
- version: info.redis_version ?? "",
259
+ version: (isValkey ? info.valkey_version : info.redis_version) ?? "",
255
260
  };
256
261
  }
257
262
  /**
@@ -1 +1,11 @@
1
1
  export declare function promiseAllN<T>(collection: Array<() => Promise<T>>, n?: number): Promise<T[]>;
2
+ /**
3
+ * Settles like `pending`, or rejects with an `Error("timeout")` once `ms`
4
+ * have elapsed. The timer is cleared either way, so a settled race leaves
5
+ * nothing armed.
6
+ *
7
+ * For calls to a server that may stop answering without closing the
8
+ * connection: ioredis then keeps the command queued until the OS gives up on
9
+ * the socket, about 10 minutes (#3181).
10
+ */
11
+ export declare function withTimeout<T>(pending: Promise<T>, ms: number): Promise<T>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.promiseAllN = promiseAllN;
4
+ exports.withTimeout = withTimeout;
4
5
  /*
5
6
  * Resolve promises with a limited concurrency number
6
7
  *
@@ -70,4 +71,25 @@ function promiseAllN(collection, n = 100) {
70
71
  }
71
72
  return pendingPromise;
72
73
  }
74
+ /**
75
+ * Settles like `pending`, or rejects with an `Error("timeout")` once `ms`
76
+ * have elapsed. The timer is cleared either way, so a settled race leaves
77
+ * nothing armed.
78
+ *
79
+ * For calls to a server that may stop answering without closing the
80
+ * connection: ioredis then keeps the command queued until the OS gives up on
81
+ * the socket, about 10 minutes (#3181).
82
+ */
83
+ async function withTimeout(pending, ms) {
84
+ let timer;
85
+ const expired = new Promise((_, reject) => {
86
+ timer = setTimeout(() => reject(new Error("timeout")), ms);
87
+ });
88
+ try {
89
+ return await Promise.race([pending, expired]);
90
+ }
91
+ finally {
92
+ clearTimeout(timer);
93
+ }
94
+ }
73
95
  //# sourceMappingURL=async.js.map
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.61.0",
4
+ "version": "2.61.1-beta.2",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
@@ -52,8 +52,8 @@
52
52
  "kuzzle-logger": "1.7.0",
53
53
  "kuzzle-plugin-auth-passport-local": "6.4.1",
54
54
  "kuzzle-sdk": ">=7.17.1 <8.0.0",
55
- "kuzzle-storage-es-7": "1.1.0",
56
- "kuzzle-storage-es-8": "1.1.0",
55
+ "kuzzle-storage-es-7": "1.1.1",
56
+ "kuzzle-storage-es-8": "1.1.1",
57
57
  "kuzzle-types": "^1.0.0",
58
58
  "kuzzle-vault": "2.2.0",
59
59
  "lodash": "4.18.1",
@@ -100,7 +100,7 @@
100
100
  "prettier": "3.9.10",
101
101
  "protobufjs-v7": "npm:protobufjs@7.5.4",
102
102
  "request-promise": "4.2.6",
103
- "semantic-release-config-kuzzle": "1.8.0",
103
+ "semantic-release-config-kuzzle": "1.9.0",
104
104
  "should": "13.2.3",
105
105
  "strip-json-comments": "5.0.3",
106
106
  "ts-node": "10.9.2",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.61.0",
4
+ "version": "2.61.1-beta.2",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
@@ -52,8 +52,8 @@
52
52
  "kuzzle-logger": "1.7.0",
53
53
  "kuzzle-plugin-auth-passport-local": "6.4.1",
54
54
  "kuzzle-sdk": ">=7.17.1 <8.0.0",
55
- "kuzzle-storage-es-7": "1.1.0",
56
- "kuzzle-storage-es-8": "1.1.0",
55
+ "kuzzle-storage-es-7": "1.1.1",
56
+ "kuzzle-storage-es-8": "1.1.1",
57
57
  "kuzzle-types": "^1.0.0",
58
58
  "kuzzle-vault": "2.2.0",
59
59
  "lodash": "4.18.1",
@@ -100,7 +100,7 @@
100
100
  "prettier": "3.9.10",
101
101
  "protobufjs-v7": "npm:protobufjs@7.5.4",
102
102
  "request-promise": "4.2.6",
103
- "semantic-release-config-kuzzle": "1.8.0",
103
+ "semantic-release-config-kuzzle": "1.9.0",
104
104
  "should": "13.2.3",
105
105
  "strip-json-comments": "5.0.3",
106
106
  "ts-node": "10.9.2",