kuzzle 2.61.1-beta.1 → 2.61.1
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
|
|
322
|
-
|
|
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)})`);
|
|
@@ -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
|
|
@@ -22,22 +23,6 @@ const redis_1 = __importDefault(require("../../service/cache/redis"));
|
|
|
22
23
|
function messageOf(thrown) {
|
|
23
24
|
return thrown instanceof Error ? thrown.message : (0, node_util_1.inspect)(thrown);
|
|
24
25
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Settles like `pending`, or rejects with `timeout` once `ms` have elapsed.
|
|
27
|
-
* The timer is cleared either way, so a settled race leaves nothing armed.
|
|
28
|
-
*/
|
|
29
|
-
async function withTimeout(pending, ms) {
|
|
30
|
-
let timer;
|
|
31
|
-
const expired = new Promise((_, reject) => {
|
|
32
|
-
timer = setTimeout(() => reject(new Error("timeout")), ms);
|
|
33
|
-
});
|
|
34
|
-
try {
|
|
35
|
-
return await Promise.race([pending, expired]);
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
clearTimeout(timer);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
26
|
class IDCardRenewer {
|
|
42
27
|
constructor() {
|
|
43
28
|
this.redis = null;
|
|
@@ -128,7 +113,7 @@ class IDCardRenewer {
|
|
|
128
113
|
// Bounded (#3181): a redis that stops answering without closing the
|
|
129
114
|
// socket leaves the command queued until the OS gives up on the TCP
|
|
130
115
|
// connection, about 10 minutes, while the card expires within seconds.
|
|
131
|
-
const refreshed = await withTimeout(this.redis.commands.pexpire(this.nodeIdKey, this.refreshDelay * this.refreshMultiplier), this.commandTimeout);
|
|
116
|
+
const refreshed = await (0, async_1.withTimeout)(this.redis.commands.pexpire(this.nodeIdKey, this.refreshDelay * this.refreshMultiplier), this.commandTimeout);
|
|
132
117
|
// Unable to refresh the key in time before it expires
|
|
133
118
|
// => this node is too slow, we need to remove it from the cluster
|
|
134
119
|
if (refreshed === 0) {
|
|
@@ -166,7 +151,7 @@ class IDCardRenewer {
|
|
|
166
151
|
try {
|
|
167
152
|
// Bounded too: a failed renewal is reported to the parent only once
|
|
168
153
|
// this returns, and the redis that made it fail is likely still mute.
|
|
169
|
-
await withTimeout(this.redis.commands.del(this.nodeIdKey), this.commandTimeout);
|
|
154
|
+
await (0, async_1.withTimeout)(this.redis.commands.del(this.nodeIdKey), this.commandTimeout);
|
|
170
155
|
}
|
|
171
156
|
catch (error) {
|
|
172
157
|
// eslint-disable-next-line no-console
|
|
@@ -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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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();
|
package/dist/lib/util/async.d.ts
CHANGED
|
@@ -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>;
|
package/dist/lib/util/async.js
CHANGED
|
@@ -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.1
|
|
4
|
+
"version": "2.61.1",
|
|
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",
|
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.1
|
|
4
|
+
"version": "2.61.1",
|
|
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",
|