From c57c5131036229bb36d2c14e6f7dfdb87cffcbd9 Mon Sep 17 00:00:00 2001 From: Sergei Grebnov Date: Mon, 22 Jan 2024 13:57:13 -0800 Subject: [PATCH] Don't retry if RESOURCE_EXHAUSTED or CANCELLED error received (#124) * don't retry for RESOURCE_EXHAUSTED and CANCELLED codes * add retry for Unknown code * bump version to 1.0.2 --- README.md | 9 +++++++-- package.json | 2 +- src/retry.ts | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 454c9dc..6c20348 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,19 @@ main(); Read more about the Spice.ai Async HTTP API at [docs.spice.ai](https://docs.spice.ai/api/sql-query-api/http-api-1). -### Configuring retry policy +### Connection retry + +From [version 1.0.1](https://github.com/spiceai/spice.js/releases/tag/v1.0.1) the `SpiceClient` implements connection retry mechanism (3 attempts by default). +The number of attempts can be configured via `setMaxRetries`: -SDK performs 3 retry attempts when using Apache Arrow Flight API. This could be configured as ``` const spiceClient = new SpiceClient('API_KEY'); spiceClient.setMaxRetries(5); // Setting to 0 will disable retries ``` +Retries are performed for connection and system internal errors. It is the SDK user's responsibility to properly +handle other errors, for example RESOURCE_EXHAUSTED (HTTP 429). + ## Documentation Check out our [API documentation](https://docs.spice.ai/sdks/node.js-sdk) to learn more about how to use the Node.js SDK. diff --git a/package.json b/package.json index a2f7248..9ff2791 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@spiceai/spice", "description": "JS + TS SDK for spice.ai", - "version": "1.0.1", + "version": "1.0.2", "engines": { "node": ">=18.0.0" }, diff --git a/src/retry.ts b/src/retry.ts index bdc54b0..691bed6 100644 --- a/src/retry.ts +++ b/src/retry.ts @@ -22,12 +22,11 @@ function shouldRetryOperationForError(err: any): boolean { } return [ - grpc.status.CANCELLED, grpc.status.UNAVAILABLE, grpc.status.DEADLINE_EXCEEDED, - grpc.status.RESOURCE_EXHAUSTED, grpc.status.ABORTED, grpc.status.INTERNAL, + grpc.status.UNKNOWN, ].includes(code); }