kuzzle 2.61.1 → 2.61.2-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.
- package/dist/lib/core/security/tokenRepository.js +4 -1
- package/dist/lib/core/shared/ObjectRepository.js +6 -0
- package/dist/lib/kerror/codes/1-services.json +6 -0
- package/dist/lib/kerror/isCacheTimeout.d.ts +7 -0
- package/dist/lib/kerror/isCacheTimeout.js +34 -0
- package/dist/lib/service/cache/redis.d.ts +6 -0
- package/dist/lib/service/cache/redis.js +30 -3
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -62,6 +62,7 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
62
62
|
const ms_1 = __importDefault(require("ms"));
|
|
63
63
|
const kerror = __importStar(require("../../kerror"));
|
|
64
64
|
const errors_1 = require("../../kerror/errors");
|
|
65
|
+
const isCacheTimeout_1 = require("../../kerror/isCacheTimeout");
|
|
65
66
|
const token_1 = require("../../model/security/token");
|
|
66
67
|
const apiKey_1 = __importDefault(require("../../model/storage/apiKey"));
|
|
67
68
|
const ObjectRepository_1 = require("../shared/ObjectRepository");
|
|
@@ -300,7 +301,9 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
300
301
|
return await this.loadForUser(userId, token);
|
|
301
302
|
}
|
|
302
303
|
catch (err) {
|
|
303
|
-
|
|
304
|
+
// The cache server not answering is a 503 the client can retry, not
|
|
305
|
+
// a verification failure (500)
|
|
306
|
+
if (err instanceof errors_1.UnauthorizedError || (0, isCacheTimeout_1.isCacheTimeout)(err)) {
|
|
304
307
|
throw err;
|
|
305
308
|
}
|
|
306
309
|
throw securityError.getFrom(err instanceof Error ? err : new Error(String(err)), "verification_error", err instanceof Error ? err.message : String(err));
|
|
@@ -55,6 +55,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.ObjectRepository = void 0;
|
|
57
57
|
const kerror = __importStar(require("../../kerror"));
|
|
58
|
+
const isCacheTimeout_1 = require("../../kerror/isCacheTimeout");
|
|
58
59
|
const cacheDbEnum_1 = require("../cache/cacheDbEnum");
|
|
59
60
|
/**
|
|
60
61
|
* `_id` is nullable because the models are: `User`, `Profile` and `Token` are
|
|
@@ -142,6 +143,11 @@ class ObjectRepository {
|
|
|
142
143
|
return await this.fromDTO({ ...JSON.parse(response) });
|
|
143
144
|
}
|
|
144
145
|
catch (err) {
|
|
146
|
+
// The cache server not answering is a 503 the client can retry, not
|
|
147
|
+
// a read failure (500)
|
|
148
|
+
if ((0, isCacheTimeout_1.isCacheTimeout)(err)) {
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
145
151
|
throw kerror.get("services", "cache", "read_failed", err instanceof Error ? err.message : String(err));
|
|
146
152
|
}
|
|
147
153
|
}
|
|
@@ -328,6 +328,12 @@
|
|
|
328
328
|
"code": 4,
|
|
329
329
|
"message": "Cache write fail: %s",
|
|
330
330
|
"class": "InternalError"
|
|
331
|
+
},
|
|
332
|
+
"timeout": {
|
|
333
|
+
"description": "The cache server did not answer within the ioredis commandTimeout",
|
|
334
|
+
"code": 5,
|
|
335
|
+
"message": "The cache server did not answer within %sms.",
|
|
336
|
+
"class": "ServiceUnavailableError"
|
|
331
337
|
}
|
|
332
338
|
}
|
|
333
339
|
},
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an error is the cache server not answering within the opt-in
|
|
3
|
+
* ioredis `commandTimeout` (`services.cache.timeout`, 503). Code that wraps
|
|
4
|
+
* cache errors into its own lets this one through, so the client gets the
|
|
5
|
+
* 503 it can retry instead of a 500.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isCacheTimeout(error: unknown): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2022 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.isCacheTimeout = isCacheTimeout;
|
|
24
|
+
const errors_1 = require("./errors");
|
|
25
|
+
/**
|
|
26
|
+
* Whether an error is the cache server not answering within the opt-in
|
|
27
|
+
* ioredis `commandTimeout` (`services.cache.timeout`, 503). Code that wraps
|
|
28
|
+
* cache errors into its own lets this one through, so the client gets the
|
|
29
|
+
* 503 it can retry instead of a 500.
|
|
30
|
+
*/
|
|
31
|
+
function isCacheTimeout(error) {
|
|
32
|
+
return error instanceof errors_1.KuzzleError && error.id === "services.cache.timeout";
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=isCacheTimeout.js.map
|
|
@@ -72,6 +72,12 @@ declare class Redis extends Service<RedisServiceConfig, RedisInfo> {
|
|
|
72
72
|
*/
|
|
73
73
|
mExecute(commands: unknown[][]): Promise<[error: Error | null, result: unknown][] | null>;
|
|
74
74
|
private _searchNodeKeys;
|
|
75
|
+
/**
|
|
76
|
+
* ioredis rejects a command its `commandTimeout` (opt-in) expired on with
|
|
77
|
+
* a plain error, which the API answered as a Kuzzle bug (500): it is the
|
|
78
|
+
* cache server not answering (503)
|
|
79
|
+
*/
|
|
80
|
+
private _cacheError;
|
|
75
81
|
private _buildClient;
|
|
76
82
|
private _buildClusterClient;
|
|
77
83
|
/**
|
|
@@ -222,7 +222,12 @@ class Redis extends service_1.default {
|
|
|
222
222
|
// job caught in `funnel.doAction`, reintroduced here by hoisting
|
|
223
223
|
// the lookup out of the call — see `pluginsManager`'s note on the
|
|
224
224
|
// same line.
|
|
225
|
-
|
|
225
|
+
try {
|
|
226
|
+
return await Reflect.apply(implementation, client, args);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
throw this._cacheError(error);
|
|
230
|
+
}
|
|
226
231
|
};
|
|
227
232
|
}
|
|
228
233
|
}
|
|
@@ -283,10 +288,15 @@ class Redis extends service_1.default {
|
|
|
283
288
|
if (!Array.isArray(commands) || commands.length === 0) {
|
|
284
289
|
return bluebird_1.default.resolve([]);
|
|
285
290
|
}
|
|
286
|
-
return this.connectedClient
|
|
291
|
+
return this.connectedClient
|
|
292
|
+
.multi(commands)
|
|
293
|
+
.exec()
|
|
294
|
+
.catch((error) => {
|
|
295
|
+
throw this._cacheError(error);
|
|
296
|
+
});
|
|
287
297
|
}
|
|
288
298
|
_searchNodeKeys(node, pattern) {
|
|
289
|
-
return new bluebird_1.default((resolve) => {
|
|
299
|
+
return new bluebird_1.default((resolve, reject) => {
|
|
290
300
|
let keys = [];
|
|
291
301
|
const stream = node.scanStream({ match: pattern });
|
|
292
302
|
stream.on("data", (resultKeys) => {
|
|
@@ -295,8 +305,25 @@ class Redis extends service_1.default {
|
|
|
295
305
|
stream.on("end", () => {
|
|
296
306
|
resolve([...new Set(keys)]);
|
|
297
307
|
});
|
|
308
|
+
// A failed `SCAN` (a `commandTimeout`, a connection lost midway)
|
|
309
|
+
// is an `error` event: unheard, it crashed the process, and the
|
|
310
|
+
// promise never settled
|
|
311
|
+
stream.on("error", (error) => reject(this._cacheError(error)));
|
|
298
312
|
});
|
|
299
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* ioredis rejects a command its `commandTimeout` (opt-in) expired on with
|
|
316
|
+
* a plain error, which the API answered as a Kuzzle bug (500): it is the
|
|
317
|
+
* cache server not answering (503)
|
|
318
|
+
*/
|
|
319
|
+
_cacheError(error) {
|
|
320
|
+
if (error instanceof Error && error.message === "Command timed out") {
|
|
321
|
+
// A number from a .kuzzlerc, a string from an environment variable
|
|
322
|
+
const delay = this._config.options?.commandTimeout;
|
|
323
|
+
return kerror.get("timeout", typeof delay === "number" || typeof delay === "string" ? delay : "?");
|
|
324
|
+
}
|
|
325
|
+
return error;
|
|
326
|
+
}
|
|
300
327
|
_buildClient(options) {
|
|
301
328
|
return new ioredis_1.default({
|
|
302
329
|
...IOREDIS_V5_DEFAULTS,
|
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.
|
|
4
|
+
"version": "2.61.2-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",
|
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.
|
|
4
|
+
"version": "2.61.2-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",
|