kuzzle 2.61.1-beta.2 → 2.61.2-beta.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.
@@ -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
  },
@@ -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
- return Reflect.apply(implementation, client, args);
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.multi(commands).exec();
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.1-beta.2",
4
+ "version": "2.61.2-beta.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-beta.2",
4
+ "version": "2.61.2-beta.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",