From 433fe2d898e2c621f47958c6cebc8bbf640d98f6 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:18:48 +0100 Subject: [PATCH 01/15] feat(design): add request timeout utilities Add fetchWithTimeout(), RequestTimeoutError and resolveRequestTimeout() to @elixir-cloud/design/utils, for the REST providers of the client packages to give each request a deadline (default 30 s, 0 for none). The deadline covers reading the body too; a signal of the caller still aborts with its own reason. Document them on a new "Request timeouts" page of the design docs. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/design-request-timeout.md | 5 + .../pages/docs/design/_meta.json | 3 +- .../pages/docs/design/request-timeouts.mdx | 73 +++++++ .../ecc-utils-design/src/utils/index.test.ts | 7 + packages/ecc-utils-design/src/utils/index.ts | 1 + .../src/utils/request-timeout.test.ts | 184 ++++++++++++++++++ .../src/utils/request-timeout.ts | 119 +++++++++++ scripts/check-design-utils.mjs | 3 + 8 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 .changeset/design-request-timeout.md create mode 100644 apps/documentation/pages/docs/design/request-timeouts.mdx create mode 100644 packages/ecc-utils-design/src/utils/request-timeout.test.ts create mode 100644 packages/ecc-utils-design/src/utils/request-timeout.ts diff --git a/.changeset/design-request-timeout.md b/.changeset/design-request-timeout.md new file mode 100644 index 00000000..089731d2 --- /dev/null +++ b/.changeset/design-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/design": minor +--- + +Add request deadlines for the REST providers of the client packages to `@elixir-cloud/design/utils`: `fetchWithTimeout()` sends a request with `fetch` and aborts it with a `RequestTimeoutError` once its deadline expires (default `DEFAULT_REQUEST_TIMEOUT`, 30 s; `0` for none), and `resolveRequestTimeout()` reads the deadline of provider options (`RestProviderOptions`, `{ timeout?: number }`). diff --git a/apps/documentation/pages/docs/design/_meta.json b/apps/documentation/pages/docs/design/_meta.json index bc577822..7bc00c68 100644 --- a/apps/documentation/pages/docs/design/_meta.json +++ b/apps/documentation/pages/docs/design/_meta.json @@ -2,5 +2,6 @@ "introduction": "Introduction", "architecture": "Architecture", "components": "Components", - "field-errors": "Field errors" + "field-errors": "Field errors", + "request-timeouts": "Request timeouts" } diff --git a/apps/documentation/pages/docs/design/request-timeouts.mdx b/apps/documentation/pages/docs/design/request-timeouts.mdx new file mode 100644 index 00000000..5b81f883 --- /dev/null +++ b/apps/documentation/pages/docs/design/request-timeouts.mdx @@ -0,0 +1,73 @@ +import { Callout } from 'nextra/components'; + +# Request timeouts + +The REST providers of the client packages give every request a deadline, so +that a request that never settles (e.g. to a server that accepts the +connection but never answers) fails instead of leaving a component loading +forever. Once the deadline expires, the request is aborted and its promise +rejects with a `RequestTimeoutError` (message `Request timed out after 30000 +ms`); components show it like any other error and fire their events as on a +failure (lists, for example, their `ecc-*-changed` event with empty data). + +The deadline covers the whole request, from sending it until its response +body has been read. It is **30 seconds** by default, set per provider with the +`timeout` option (in milliseconds; `0` for none): + +```ts +import { RestTrsProvider } from '@elixir-cloud/trs/providers'; + +// 10 s for each request +const provider = new RestTrsProvider('https://trs.example.org/ga4gh/trs/v2', { + timeout: 10_000, +}); +``` + +Components that create their REST provider from `baseUrl` use the default. +To set another deadline, pass them a provider instead. + +The REST providers of these packages have the option: +[Cloud Registry](/docs/cloud-registry/providers), +[Service Registry](/docs/service-registry/providers), +[TES](/docs/tes/providers), [WES](/docs/wes/providers), +[TRS](/docs/trs/providers), [TRS-Filer](/docs/trs-filer/providers), DRS +(`RestDrsProvider`) and DRS-Filer (`RestDrsFilerProvider`). + + + A provider that overrides `fetch()` and calls `super.fetch()` (e.g. to add an `Authorization` + header) keeps the deadline. A `signal` passed in the request options still aborts the request, + with its own reason. + + + + Custom providers that implement a provider interface without extending a REST provider set their + own deadlines. Their methods should reject, not stay pending, when a request can't complete: a + promise that never settles leaves the component loading. `fetchWithTimeout()` of + `@elixir-cloud/design/utils` (below) does this for `fetch`. + + +## Utilities + +`@elixir-cloud/design/utils` (which registers no components) exports what +the REST providers use: + +| Export | Description | +| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `fetchWithTimeout(input, init?, timeout?)` | `fetch` with a deadline in milliseconds (default 30 s, `0` for none); aborts with a `RequestTimeoutError` once it expires. A `signal` in `init` or of a `Request` still aborts with its own reason. | +| `RequestTimeoutError` | The error of an expired request, with `name` `RequestTimeoutError` and the deadline as `timeout`. | +| `resolveRequestTimeout(options?)` | The deadline of provider options (`{ timeout?: number }`): the default if unset; throws a `RangeError` unless it is an integer from `0` to `MAX_REQUEST_TIMEOUT`. | +| `DEFAULT_REQUEST_TIMEOUT` | `30000` (30 s). | +| `MAX_REQUEST_TIMEOUT` | `2147483647` (about 24.8 days), the longest deadline timers support. | +| `RestProviderOptions` | Type of the options (`{ timeout?: number }`). | + +```ts +import { RequestTimeoutError } from '@elixir-cloud/design/utils'; + +try { + await provider.getServiceInfo(); +} catch (error) { + if (error instanceof RequestTimeoutError) { + // The server didn't answer within error.timeout ms + } +} +``` diff --git a/packages/ecc-utils-design/src/utils/index.test.ts b/packages/ecc-utils-design/src/utils/index.test.ts index 5e3a85bf..7a2f32b3 100644 --- a/packages/ecc-utils-design/src/utils/index.test.ts +++ b/packages/ecc-utils-design/src/utils/index.test.ts @@ -12,6 +12,13 @@ describe("utils entry point", () => { expect(utils.normalizePointer).to.be.a("function"); }); + it("exports the request timeout utilities", () => { + expect(utils.fetchWithTimeout).to.be.a("function"); + expect(utils.resolveRequestTimeout).to.be.a("function"); + expect(utils.RequestTimeoutError).to.be.a("function"); + expect(utils.DEFAULT_REQUEST_TIMEOUT).to.equal(30_000); + }); + it("registers no components", () => { ["input", "checkbox", "code", "select"].forEach((name) => { expect(customElements.get(`ecc-utils-design-${name}`)).to.equal( diff --git a/packages/ecc-utils-design/src/utils/index.ts b/packages/ecc-utils-design/src/utils/index.ts index d508a2cc..372cf0a4 100644 --- a/packages/ecc-utils-design/src/utils/index.ts +++ b/packages/ecc-utils-design/src/utils/index.ts @@ -1 +1,2 @@ export * from "./problem-details.js"; +export * from "./request-timeout.js"; diff --git a/packages/ecc-utils-design/src/utils/request-timeout.test.ts b/packages/ecc-utils-design/src/utils/request-timeout.test.ts new file mode 100644 index 00000000..0401923c --- /dev/null +++ b/packages/ecc-utils-design/src/utils/request-timeout.test.ts @@ -0,0 +1,184 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + MAX_REQUEST_TIMEOUT, + RequestTimeoutError, + fetchWithTimeout, + resolveRequestTimeout, +} from "./index.js"; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +function neverAnswer(_input: RequestInfo | URL, init: RequestInit = {}) { + return new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); +} + +/** Resolves with the rejection reason of a promise, fails if it fulfils. */ +async function rejectionOf(promise: Promise): Promise { + try { + await promise; + } catch (error) { + return error; + } + throw new Error("Expected the promise to reject"); +} + +describe("resolveRequestTimeout()", () => { + it("defaults to 30 s", () => { + expect(DEFAULT_REQUEST_TIMEOUT).to.equal(30_000); + expect(resolveRequestTimeout()).to.equal(DEFAULT_REQUEST_TIMEOUT); + expect(resolveRequestTimeout({})).to.equal(DEFAULT_REQUEST_TIMEOUT); + }); + + it("returns a valid timeout as given", () => { + expect(resolveRequestTimeout({ timeout: 0 })).to.equal(0); + expect(resolveRequestTimeout({ timeout: 5000 })).to.equal(5000); + expect(resolveRequestTimeout({ timeout: MAX_REQUEST_TIMEOUT })).to.equal( + MAX_REQUEST_TIMEOUT + ); + }); + + [-1, 1.5, Number.NaN, Infinity, MAX_REQUEST_TIMEOUT + 1].forEach( + (timeout) => { + it(`rejects ${timeout}`, () => { + expect(() => resolveRequestTimeout({ timeout })).to.throw(RangeError); + }); + } + ); +}); + +describe("fetchWithTimeout()", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("passes the request and its options on", async () => { + fetchStub.callsFake(async () => new Response("ok")); + + const response = await fetchWithTimeout( + "https://api.example.org/things", + { method: "POST", headers: { "X-Test": "1" } }, + 1000 + ); + + expect(await response.text()).to.equal("ok"); + const [input, init] = fetchStub.firstCall.args; + expect(input).to.equal("https://api.example.org/things"); + expect(init.method).to.equal("POST"); + expect(init.headers).to.deep.equal({ "X-Test": "1" }); + expect(init.signal).to.be.instanceOf(AbortSignal); + }); + + it("rejects with a RequestTimeoutError once the deadline expires", async () => { + const error = await rejectionOf( + fetchWithTimeout("https://api.example.org/things", {}, 20) + ); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as RequestTimeoutError).name).to.equal("RequestTimeoutError"); + expect((error as RequestTimeoutError).timeout).to.equal(20); + expect((error as Error).message).to.equal("Request timed out after 20 ms"); + }); + + it("keeps the deadline after the response arrived", async () => { + // `fetch` aborts reading the body with the reason of its signal + fetchStub.callsFake(async () => new Response("ok")); + + await fetchWithTimeout("https://api.example.org/things", {}, 20); + const { signal } = fetchStub.firstCall.args[1] as RequestInit; + expect(signal?.aborted).to.equal(false); + await new Promise((resolve) => { + signal?.addEventListener("abort", resolve); + }); + + expect(signal?.reason).to.be.instanceOf(RequestTimeoutError); + }); + + it("sets no deadline for a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("ok")); + + await fetchWithTimeout("https://api.example.org/things", {}, 0); + + expect(fetchStub.firstCall.args[1].signal).to.equal(undefined); + }); + + it("defaults to 30 s", async () => { + const clock = sinon.useFakeTimers({ toFake: ["setTimeout"] }); + const request = rejectionOf( + fetchWithTimeout("https://api.example.org/things") + ); + + clock.tick(DEFAULT_REQUEST_TIMEOUT - 1); + let settled = false; + request.then(() => { + settled = true; + }); + await Promise.resolve(); + expect(settled).to.equal(false); + + clock.tick(1); + expect(await request).to.be.instanceOf(RequestTimeoutError); + }); + + it("aborts with the reason of the caller's signal", async () => { + const caller = new AbortController(); + const request = rejectionOf( + fetchWithTimeout( + "https://api.example.org/things", + { signal: caller.signal }, + 1000 + ) + ); + + caller.abort(new Error("cancelled")); + + expect(((await request) as Error).message).to.equal("cancelled"); + }); + + it("aborts at once with a signal that is already aborted", async () => { + const caller = new AbortController(); + caller.abort(new Error("cancelled")); + fetchStub.callsFake(async (_input, init: RequestInit) => { + if (init.signal?.aborted) { + throw init.signal.reason; + } + return new Response("ok"); + }); + + const error = await rejectionOf( + fetchWithTimeout( + "https://api.example.org/things", + { signal: caller.signal }, + 1000 + ) + ); + + expect((error as Error).message).to.equal("cancelled"); + }); + + it("follows the signal of a Request", async () => { + const caller = new AbortController(); + const request = rejectionOf( + fetchWithTimeout( + new Request("https://api.example.org/things", { + signal: caller.signal, + }), + {}, + 1000 + ) + ); + + caller.abort(new Error("cancelled")); + + expect(((await request) as Error).message).to.equal("cancelled"); + }); +}); diff --git a/packages/ecc-utils-design/src/utils/request-timeout.ts b/packages/ecc-utils-design/src/utils/request-timeout.ts new file mode 100644 index 00000000..1adb8c14 --- /dev/null +++ b/packages/ecc-utils-design/src/utils/request-timeout.ts @@ -0,0 +1,119 @@ +/** + * Request deadlines for the REST providers of the client packages, so that a + * request that never settles (e.g. to a server that accepts the connection + * but never answers) rejects, and components show their usual error instead + * of loading forever. + * + * The deadline covers the whole request: from sending it until its response + * body has been read (`response.json()` and the like reject too once it has + * expired). + */ + +/** `AbortSignal` with its abort reason (newer than TypeScript 4.3's DOM). */ +interface AbortSignalWithReason extends AbortSignal { + readonly reason: unknown; +} + +/** `AbortController` that aborts with a reason. */ +interface AbortControllerWithReason extends AbortController { + readonly signal: AbortSignalWithReason; + abort(reason?: unknown): void; +} + +/** Default deadline of a request of the REST providers: 30 s. */ +export const DEFAULT_REQUEST_TIMEOUT = 30_000; + +/** + * Longest deadline that timers support (2^31 - 1 ms, about 24.8 days); + * longer ones would expire at once. + */ +export const MAX_REQUEST_TIMEOUT = 2_147_483_647; + +/** Options of the REST providers of the client packages. */ +export interface RestProviderOptions { + /** + * Deadline of each request in milliseconds, until its response body has + * been read; `0` for none. Defaults to `DEFAULT_REQUEST_TIMEOUT` (30 s). + */ + timeout?: number; +} + +/** Reason of a request that was aborted because its deadline expired. */ +export class RequestTimeoutError extends Error { + /** The deadline that expired, in milliseconds. */ + readonly timeout: number; + + constructor(timeout: number) { + super(`Request timed out after ${timeout} ms`); + this.name = "RequestTimeoutError"; + this.timeout = timeout; + } +} + +/** + * Returns the request deadline of the given provider options: the default if + * none is set, else the value. + * @param options Options of a REST provider + * @returns Deadline in milliseconds, `0` for none + * @throws {RangeError} If the timeout is not an integer from `0` to + * `MAX_REQUEST_TIMEOUT` + */ +export function resolveRequestTimeout( + options: RestProviderOptions = {} +): number { + const { timeout = DEFAULT_REQUEST_TIMEOUT } = options; + if ( + !Number.isInteger(timeout) || + timeout < 0 || + timeout > MAX_REQUEST_TIMEOUT + ) { + throw new RangeError( + `timeout must be an integer from 0 to ${MAX_REQUEST_TIMEOUT} (ms), got ${timeout}` + ); + } + return timeout; +} + +/** + * Sends a request with `fetch` that is aborted with a `RequestTimeoutError` + * once the deadline expires. A `signal` of the request still aborts it, with + * its own reason. + * @param input Resource to fetch + * @param init Options of the request + * @param timeout Deadline in milliseconds (as by `resolveRequestTimeout()`), + * `0` for none + * @returns The response, as from `fetch` + */ +export function fetchWithTimeout( + input: RequestInfo | URL, + init: RequestInit = {}, + timeout: number = DEFAULT_REQUEST_TIMEOUT +): Promise { + // Typed for the DOM library of TypeScript 4.3, which the packages build + // with: it lacks `URL` inputs, `abort(reason)` and `signal.reason` + const request = input as RequestInfo; + if (timeout === 0) { + return fetch(request, init); + } + const controller = new AbortController() as AbortControllerWithReason; + const timer = setTimeout( + () => controller.abort(new RequestTimeoutError(timeout)), + timeout + ); + const signal = (init.signal ?? + (input instanceof Request ? input.signal : undefined)) as + | AbortSignalWithReason + | undefined; + if (signal) { + const abort = () => { + clearTimeout(timer); + controller.abort(signal.reason); + }; + if (signal.aborted) { + abort(); + } else { + signal.addEventListener("abort", abort, { once: true }); + } + } + return fetch(request, { ...init, signal: controller.signal }); +} diff --git a/scripts/check-design-utils.mjs b/scripts/check-design-utils.mjs index c4d276b1..72ca9378 100644 --- a/scripts/check-design-utils.mjs +++ b/scripts/check-design-utils.mjs @@ -6,10 +6,13 @@ const utils = await import("@elixir-cloud/design/utils"); const expected = [ + "RequestTimeoutError", + "fetchWithTimeout", "mapFieldErrors", "normalizePointer", "parseProblemDetails", "readProblemDetails", + "resolveRequestTimeout", ]; const missing = expected.filter((name) => typeof utils[name] !== "function"); if (missing.length > 0) { From bef07be02bb11b87a154405b1adcdd69b2fcb868 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:21:15 +0100 Subject: [PATCH 02/15] feat(service-registry): time out REST requests RestServiceRegistryProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .../service-registry-request-timeout.md | 5 ++ .../pages/docs/service-registry/providers.mdx | 5 +- .../services/tests/services-provider.test.ts | 25 ++++++++ .../src/providers/rest-sr-provider.ts | 29 +++++++-- .../providers/tests/rest-sr-provider.test.ts | 61 +++++++++++++++++++ 5 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 .changeset/service-registry-request-timeout.md diff --git a/.changeset/service-registry-request-timeout.md b/.changeset/service-registry-request-timeout.md new file mode 100644 index 00000000..4a87b585 --- /dev/null +++ b/.changeset/service-registry-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/service-registry": minor +--- + +Time out the requests of `RestServiceRegistryProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestServiceRegistryProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/apps/documentation/pages/docs/service-registry/providers.mdx b/apps/documentation/pages/docs/service-registry/providers.mdx index 5d9529a6..f15b479c 100644 --- a/apps/documentation/pages/docs/service-registry/providers.mdx +++ b/apps/documentation/pages/docs/service-registry/providers.mdx @@ -35,11 +35,12 @@ The `RestServiceRegistryProvider` is the main implementation that communicates w ### Constructor ```typescript -constructor(baseUrl: string) +constructor(baseUrl: string, options?: { timeout?: number }) ``` **Parameters:** - `baseUrl`: The base URL of the Service Registry API endpoint (e.g., `https://registry.example.com/ga4gh/registry/v1`) +- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -263,6 +264,8 @@ class CustomServiceRegistryProvider extends RestServiceRegistryProvider { } ``` +Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `ServiceRegistryProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). + For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/packages/ecc-client-ga4gh-service-registry/src/components/services/tests/services-provider.test.ts b/packages/ecc-client-ga4gh-service-registry/src/components/services/tests/services-provider.test.ts index 1fb39aeb..e2cb692b 100644 --- a/packages/ecc-client-ga4gh-service-registry/src/components/services/tests/services-provider.test.ts +++ b/packages/ecc-client-ga4gh-service-registry/src/components/services/tests/services-provider.test.ts @@ -42,6 +42,12 @@ const deferred = () => { return { promise, resolve: settleWith }; }; +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + /** The services the component shows. */ const shown = (el: ECCClientGa4ghServiceRegistryServices) => (el as unknown as { services: ExternalService[] }).services; @@ -252,6 +258,25 @@ describe("ecc-client-ga4gh-service-registry-services provider", () => { expect(reported).to.deep.equal([[]]); }); + it("shows the error of an expired request and reports no services", async () => { + fetchStub.callsFake(neverAnswer); + const provider = new RestServiceRegistryProvider(BASE_URL, { + timeout: 20, + }); + const el = await fixture( + html`` + ); + const changed = oneEvent(el, "ecc-services-changed"); + + expect((await changed).detail.services).to.deep.equal([]); + await waitUntil(() => + el.shadowRoot?.textContent?.includes("Request timed out after 20 ms") + ); + expect(shown(el)).to.deep.equal([]); + }); + it("starts on the first page with a provider that replaces the first one", async () => { const first = stubProvider(); const second = stubProvider([service("b")]); diff --git a/packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts b/packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts index 293b6491..a930989d 100644 --- a/packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts +++ b/packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { ServiceRegistryProvider, ExternalService, @@ -10,16 +15,28 @@ import { * This class combines the functionality of ServiceRegistryAPI and RestServiceRegistryProvider */ export class RestServiceRegistryProvider implements ServiceRegistryProvider { - // eslint-disable-next-line no-useless-constructor - constructor(public readonly baseUrl: string) {} + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the Service Registry API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor( + public readonly baseUrl: string, + options: RestProviderOptions = {} + ) { + this.timeout = resolveRequestTimeout(options); + } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } /** diff --git a/packages/ecc-client-ga4gh-service-registry/src/providers/tests/rest-sr-provider.test.ts b/packages/ecc-client-ga4gh-service-registry/src/providers/tests/rest-sr-provider.test.ts index 03dfeb81..1338a58d 100644 --- a/packages/ecc-client-ga4gh-service-registry/src/providers/tests/rest-sr-provider.test.ts +++ b/packages/ecc-client-ga4gh-service-registry/src/providers/tests/rest-sr-provider.test.ts @@ -1,6 +1,10 @@ /* eslint-disable import/no-extraneous-dependencies */ import { expect } from "@open-wc/testing"; import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; import { RestServiceRegistryProvider } from "../rest-sr-provider.js"; const BASE_URL = "https://registry.example.org/ga4gh/registry/v1"; @@ -32,6 +36,13 @@ const CALLS: Call[] = [ ["getServiceInfo", (p) => p.getServiceInfo(), `${BASE_URL}/service-info`], ]; +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +function neverAnswer(_input: RequestInfo | URL, init: RequestInit = {}) { + return new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); +} + describe("RestServiceRegistryProvider", () => { let fetchStub: sinon.SinonStub; @@ -80,4 +91,54 @@ describe("RestServiceRegistryProvider", () => { expect(headers.get("Authorization")).to.equal("Bearer test-token"); }); }); + + it("times out requests after 30 s by default", () => { + expect(new RestServiceRegistryProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect( + () => new RestServiceRegistryProvider(BASE_URL, { timeout: -1 }) + ).to.throw(RangeError); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + fetchStub.callsFake(neverAnswer); + + let error: unknown; + try { + await call(new RestServiceRegistryProvider(BASE_URL, { timeout: 20 })); + } catch (e) { + error = e; + } + + expect(error).to.be.instanceOf(RequestTimeoutError); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + fetchStub.callsFake(neverAnswer); + + let error: unknown; + try { + await new TokenServiceRegistryProvider(BASE_URL, { + timeout: 20, + }).getServices(); + } catch (e) { + error = e; + } + + expect(error).to.be.instanceOf(RequestTimeoutError); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + await new RestServiceRegistryProvider(BASE_URL, { + timeout: 0, + }).getServices(); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); }); From 1bdc506bb5734edb158adc5326da7cef378768c3 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:43:45 +0100 Subject: [PATCH 03/15] feat(cloud-registry): time out REST requests RestCloudRegistryProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/cloud-registry-request-timeout.md | 5 + .../pages/docs/cloud-registry/providers.mdx | 5 +- .../src/providers/rest-cr-provider.ts | 29 ++++-- .../tests/rest-cr-provider-timeout.test.ts | 96 +++++++++++++++++++ 4 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 .changeset/cloud-registry-request-timeout.md create mode 100644 packages/ecc-client-elixir-cloud-registry/src/providers/tests/rest-cr-provider-timeout.test.ts diff --git a/.changeset/cloud-registry-request-timeout.md b/.changeset/cloud-registry-request-timeout.md new file mode 100644 index 00000000..abb60195 --- /dev/null +++ b/.changeset/cloud-registry-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/cloud-registry": minor +--- + +Time out the requests of `RestCloudRegistryProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestCloudRegistryProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/apps/documentation/pages/docs/cloud-registry/providers.mdx b/apps/documentation/pages/docs/cloud-registry/providers.mdx index 9e1ef6e8..12b6bcdb 100644 --- a/apps/documentation/pages/docs/cloud-registry/providers.mdx +++ b/apps/documentation/pages/docs/cloud-registry/providers.mdx @@ -49,11 +49,12 @@ The `RestCloudRegistryProvider` is the main implementation that communicates wit ### Constructor ```typescript -constructor(baseUrl: string) +constructor(baseUrl: string, options?: { timeout?: number }) ``` **Parameters:** - `baseUrl`: The base URL of the Cloud Registry API endpoint (e.g., `https://cloud-registry.example.com/ga4gh/registry/v1`) +- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -425,6 +426,8 @@ class CustomCloudRegistryProvider extends RestCloudRegistryProvider { } ``` +Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `CloudRegistryProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). + For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts b/packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts index 8c6e7857..c0eadb08 100644 --- a/packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts +++ b/packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { CloudRegistryProvider, ExternalService, @@ -19,16 +24,28 @@ import { CloudRegistryError } from "./errors.js"; * with an error status; it carries the status and the problem details. */ export class RestCloudRegistryProvider implements CloudRegistryProvider { - // eslint-disable-next-line no-useless-constructor - constructor(public readonly baseUrl: string) {} + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the Cloud Registry API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor( + public readonly baseUrl: string, + options: RestProviderOptions = {} + ) { + this.timeout = resolveRequestTimeout(options); + } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } /** diff --git a/packages/ecc-client-elixir-cloud-registry/src/providers/tests/rest-cr-provider-timeout.test.ts b/packages/ecc-client-elixir-cloud-registry/src/providers/tests/rest-cr-provider-timeout.test.ts new file mode 100644 index 00000000..fe5d0ba0 --- /dev/null +++ b/packages/ecc-client-elixir-cloud-registry/src/providers/tests/rest-cr-provider-timeout.test.ts @@ -0,0 +1,96 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; +import { RestCloudRegistryProvider } from "../rest-cr-provider.js"; + +const BASE_URL = "https://registry.example.org/ga4gh/registry/v1"; + +/** Provider that adds a bearer token to every request, as in the docs. */ +class TokenProvider extends RestCloudRegistryProvider { + protected fetch(input: RequestInfo | URL, init: RequestInit = {}) { + const headers = new Headers(init.headers); + headers.set("Authorization", "Bearer test-token"); + return super.fetch(input, { ...init, headers }); + } +} + +/** Provider methods, one of each kind of request. */ +const CALLS: [string, (p: RestCloudRegistryProvider) => Promise][] = [ + ["getServices", (p) => p.getServices()], + ["deleteService", (p) => p.deleteService("service-1")], +]; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + +/** The error that a call rejects with. */ +const rejection = async (call: () => Promise): Promise => { + try { + await call(); + } catch (err) { + return err; + } + throw new Error("Expected the call to reject"); +}; + +describe("RestCloudRegistryProvider request timeout", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("defaults to 30 s", () => { + expect(new RestCloudRegistryProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect( + () => new RestCloudRegistryProvider(BASE_URL, { timeout: -1 }) + ).to.throw(RangeError); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + const provider = new RestCloudRegistryProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => call(provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as Error).message).to.equal( + "Request timed out after 20 ms" + ); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + const provider = new TokenProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => CALLS[0][1](provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + const headers = new Headers(fetchStub.firstCall.args[1]?.headers); + expect(headers.get("Authorization")).to.equal("Bearer test-token"); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("{}", { status: 200 })); + + await CALLS[0][1](new RestCloudRegistryProvider(BASE_URL, { timeout: 0 })); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); +}); From 94b35b3571340ad7c902dc6c69a410dc1536115d Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:48:08 +0100 Subject: [PATCH 04/15] feat(tes): time out REST requests RestTesProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/tes-request-timeout.md | 5 + .../pages/docs/tes/providers.mdx | 5 +- .../src/components/runs/runs.test.ts | 26 +++++ .../src/providers/rest-tes-provider.ts | 24 ++++- .../tests/rest-tes-provider-timeout.test.ts | 96 +++++++++++++++++++ 5 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 .changeset/tes-request-timeout.md create mode 100644 packages/ecc-client-ga4gh-tes/src/providers/tests/rest-tes-provider-timeout.test.ts diff --git a/.changeset/tes-request-timeout.md b/.changeset/tes-request-timeout.md new file mode 100644 index 00000000..33c43bab --- /dev/null +++ b/.changeset/tes-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/tes": minor +--- + +Time out the requests of `RestTesProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestTesProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/apps/documentation/pages/docs/tes/providers.mdx b/apps/documentation/pages/docs/tes/providers.mdx index 95de9ac8..cea55f17 100644 --- a/apps/documentation/pages/docs/tes/providers.mdx +++ b/apps/documentation/pages/docs/tes/providers.mdx @@ -34,12 +34,13 @@ The `RestTesProvider` is the main implementation that communicates with TES APIs ### Constructor ```typescript -constructor(baseUrl: string) +constructor(baseUrl: string, options?: { timeout?: number }) ``` **Parameters:** - `baseUrl`: The base URL of the TES API endpoint (e.g., `https://protes.rahtiapp.fi/ga4gh/tes/v1`) +- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -454,6 +455,8 @@ const provider = new AuthTesProvider( Tokens used in browser code are visible to users. Prefer short-lived tokens, and never embed long-lived secrets in client-side bundles. +Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `TesProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). + For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/packages/ecc-client-ga4gh-tes/src/components/runs/runs.test.ts b/packages/ecc-client-ga4gh-tes/src/components/runs/runs.test.ts index d44325e7..44613ecc 100644 --- a/packages/ecc-client-ga4gh-tes/src/components/runs/runs.test.ts +++ b/packages/ecc-client-ga4gh-tes/src/components/runs/runs.test.ts @@ -7,6 +7,13 @@ import type { Task, ServiceInfo, } from "../../providers/tes-provider.js"; +import { RestTesProvider } from "../../providers/rest-tes-provider.js"; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); const tasks: Task[] = [ { id: "task-1", name: "first", state: "RUNNING" }, @@ -345,4 +352,23 @@ describe("ecc-client-ga4gh-tes-runs", () => { ) ).to.equal(null); }); + + it("shows the error of an expired request", async () => { + const originalFetch = window.fetch; + window.fetch = neverAnswer as typeof fetch; + try { + const el = await fixture( + html`` + ); + await waitUntil(() => + el.shadowRoot!.textContent!.includes("Request timed out after 20 ms") + ); + } finally { + window.fetch = originalFetch; + } + }); }); diff --git a/packages/ecc-client-ga4gh-tes/src/providers/rest-tes-provider.ts b/packages/ecc-client-ga4gh-tes/src/providers/rest-tes-provider.ts index b9c276e8..9ffd7061 100644 --- a/packages/ecc-client-ga4gh-tes/src/providers/rest-tes-provider.ts +++ b/packages/ecc-client-ga4gh-tes/src/providers/rest-tes-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { TesProvider, ServiceInfo, @@ -17,17 +22,26 @@ import { export class RestTesProvider implements TesProvider { private baseUrl: string; - constructor(baseUrl: string) { + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the TES API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor(baseUrl: string, options: RestProviderOptions = {}) { this.baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl; + this.timeout = resolveRequestTimeout(options); } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } private static async handleResponse(response: Response): Promise { diff --git a/packages/ecc-client-ga4gh-tes/src/providers/tests/rest-tes-provider-timeout.test.ts b/packages/ecc-client-ga4gh-tes/src/providers/tests/rest-tes-provider-timeout.test.ts new file mode 100644 index 00000000..304e4351 --- /dev/null +++ b/packages/ecc-client-ga4gh-tes/src/providers/tests/rest-tes-provider-timeout.test.ts @@ -0,0 +1,96 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; +import { RestTesProvider } from "../rest-tes-provider.js"; + +const BASE_URL = "https://tes.example.org/ga4gh/tes/v1"; + +/** Provider that adds a bearer token to every request, as in the docs. */ +class TokenProvider extends RestTesProvider { + protected fetch(input: RequestInfo | URL, init: RequestInit = {}) { + const headers = new Headers(init.headers); + headers.set("Authorization", "Bearer test-token"); + return super.fetch(input, { ...init, headers }); + } +} + +/** Provider methods, one of each kind of request. */ +const CALLS: [string, (p: RestTesProvider) => Promise][] = [ + ["listTasks", (p) => p.listTasks()], + ["cancelTask", (p) => p.cancelTask("task-1")], +]; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + +/** The error that a call rejects with. */ +const rejection = async (call: () => Promise): Promise => { + try { + await call(); + } catch (err) { + return err; + } + throw new Error("Expected the call to reject"); +}; + +describe("RestTesProvider request timeout", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("defaults to 30 s", () => { + expect(new RestTesProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect(() => new RestTesProvider(BASE_URL, { timeout: -1 })).to.throw( + RangeError + ); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + const provider = new RestTesProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => call(provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as Error).message).to.equal( + "Request timed out after 20 ms" + ); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + const provider = new TokenProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => CALLS[0][1](provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + const headers = new Headers(fetchStub.firstCall.args[1]?.headers); + expect(headers.get("Authorization")).to.equal("Bearer test-token"); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("{}", { status: 200 })); + + await CALLS[0][1](new RestTesProvider(BASE_URL, { timeout: 0 })); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); +}); From cca4150f885a69ee1e2504269f7a1699ea5cf74c Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:50:19 +0100 Subject: [PATCH 05/15] feat(wes): time out REST requests RestWesProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/wes-request-timeout.md | 5 + .../pages/docs/wes/providers.mdx | 5 +- .../src/providers/rest-wes-provider.ts | 24 ++++- .../tests/rest-wes-provider-timeout.test.ts | 96 +++++++++++++++++++ 4 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 .changeset/wes-request-timeout.md create mode 100644 packages/ecc-client-ga4gh-wes/src/providers/tests/rest-wes-provider-timeout.test.ts diff --git a/.changeset/wes-request-timeout.md b/.changeset/wes-request-timeout.md new file mode 100644 index 00000000..fab8d72a --- /dev/null +++ b/.changeset/wes-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/wes": minor +--- + +Time out the requests of `RestWesProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestWesProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. The deadline includes uploading the attachments of `runWorkflow()`: raise it for large attachments. diff --git a/apps/documentation/pages/docs/wes/providers.mdx b/apps/documentation/pages/docs/wes/providers.mdx index 0cec1627..253ed1a0 100644 --- a/apps/documentation/pages/docs/wes/providers.mdx +++ b/apps/documentation/pages/docs/wes/providers.mdx @@ -33,11 +33,12 @@ The `RestWesProvider` is the main implementation that communicates with WES APIs ### Constructor ```typescript -constructor(baseUrl: string) +constructor(baseUrl: string, options?: { timeout?: number }) ``` **Parameters:** - `baseUrl`: The base URL of the WES API endpoint (e.g., `https://weskit.example.com/ga4gh/wes/v1`) +- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). The deadline includes uploading the attachments of `runWorkflow()`: raise it for large attachments. ### Basic Usage @@ -349,6 +350,8 @@ class CustomWesProvider extends RestWesProvider { } ``` +Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `WesProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). + For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts b/packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts index f0b5340a..a3fc3614 100644 --- a/packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts +++ b/packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { WesProvider, ServiceInfo, @@ -16,17 +21,26 @@ import { export class RestWesProvider implements WesProvider { protected baseUrl: string; - constructor(baseUrl: string) { + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the WES API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor(baseUrl: string, options: RestProviderOptions = {}) { this.baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl; + this.timeout = resolveRequestTimeout(options); } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } private static async handleResponse(response: Response): Promise { diff --git a/packages/ecc-client-ga4gh-wes/src/providers/tests/rest-wes-provider-timeout.test.ts b/packages/ecc-client-ga4gh-wes/src/providers/tests/rest-wes-provider-timeout.test.ts new file mode 100644 index 00000000..32412174 --- /dev/null +++ b/packages/ecc-client-ga4gh-wes/src/providers/tests/rest-wes-provider-timeout.test.ts @@ -0,0 +1,96 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; +import { RestWesProvider } from "../rest-wes-provider.js"; + +const BASE_URL = "https://wes.example.org/ga4gh/wes/v1"; + +/** Provider that adds a bearer token to every request, as in the docs. */ +class TokenProvider extends RestWesProvider { + protected fetch(input: RequestInfo | URL, init: RequestInit = {}) { + const headers = new Headers(init.headers); + headers.set("Authorization", "Bearer test-token"); + return super.fetch(input, { ...init, headers }); + } +} + +/** Provider methods, one of each kind of request. */ +const CALLS: [string, (p: RestWesProvider) => Promise][] = [ + ["getServiceInfo", (p) => p.getServiceInfo()], + ["getRunLog", (p) => p.getRunLog("run-1")], +]; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + +/** The error that a call rejects with. */ +const rejection = async (call: () => Promise): Promise => { + try { + await call(); + } catch (err) { + return err; + } + throw new Error("Expected the call to reject"); +}; + +describe("RestWesProvider request timeout", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("defaults to 30 s", () => { + expect(new RestWesProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect(() => new RestWesProvider(BASE_URL, { timeout: -1 })).to.throw( + RangeError + ); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + const provider = new RestWesProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => call(provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as Error).message).to.equal( + "Request timed out after 20 ms" + ); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + const provider = new TokenProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => CALLS[0][1](provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + const headers = new Headers(fetchStub.firstCall.args[1]?.headers); + expect(headers.get("Authorization")).to.equal("Bearer test-token"); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("{}", { status: 200 })); + + await CALLS[0][1](new RestWesProvider(BASE_URL, { timeout: 0 })); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); +}); From 16243c3988e162e4a01646b6fa3c3faac118382a Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:52:44 +0100 Subject: [PATCH 06/15] feat(trs): time out REST requests RestTrsProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/trs-request-timeout.md | 5 + .../pages/docs/trs/providers.mdx | 5 +- .../src/components/tools/tests/tools.test.ts | 24 +++++ .../src/providers/rest-trs-provider.ts | 29 ++++-- .../tests/rest-trs-provider-timeout.test.ts | 95 +++++++++++++++++++ 5 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 .changeset/trs-request-timeout.md create mode 100644 packages/ecc-client-ga4gh-trs/src/providers/tests/rest-trs-provider-timeout.test.ts diff --git a/.changeset/trs-request-timeout.md b/.changeset/trs-request-timeout.md new file mode 100644 index 00000000..b86dceae --- /dev/null +++ b/.changeset/trs-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/trs": minor +--- + +Time out the requests of `RestTrsProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestTrsProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/apps/documentation/pages/docs/trs/providers.mdx b/apps/documentation/pages/docs/trs/providers.mdx index 6fad01c3..2a26ddcb 100644 --- a/apps/documentation/pages/docs/trs/providers.mdx +++ b/apps/documentation/pages/docs/trs/providers.mdx @@ -64,11 +64,12 @@ The `RestTrsProvider` is the main implementation that communicates with TRS APIs ### Constructor ```typescript -constructor(baseUrl: string) +constructor(baseUrl: string, options?: { timeout?: number }) ``` **Parameters:** - `baseUrl`: The base URL of the TRS API endpoint (e.g., `https://dockstore.org/api/ga4gh/trs/v2`) +- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -470,6 +471,8 @@ class CustomTrsProvider extends RestTrsProvider { } ``` +Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `TrsProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). + For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/packages/ecc-client-ga4gh-trs/src/components/tools/tests/tools.test.ts b/packages/ecc-client-ga4gh-trs/src/components/tools/tests/tools.test.ts index f34d54a1..0b35fb13 100644 --- a/packages/ecc-client-ga4gh-trs/src/components/tools/tests/tools.test.ts +++ b/packages/ecc-client-ga4gh-trs/src/components/tools/tests/tools.test.ts @@ -4,6 +4,13 @@ import sinon from "sinon"; import "../index.js"; import type { ECCClientGa4ghTrsTools } from "../tools.js"; import type { Tool, ToolClass, TrsProvider } from "../../../providers/index.js"; +import { RestTrsProvider } from "../../../providers/rest-trs-provider.js"; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); const BASE_URL = "https://trs.example.org/ga4gh/trs/v2"; const OTHER_URL = "https://other.example.org/ga4gh/trs/v2"; @@ -260,4 +267,21 @@ describe("ecc-client-ga4gh-trs-tools provider", () => { expect(el.shadowRoot?.textContent).not.to.contain("Unavailable"); expect(reported).to.deep.equal([]); }); + + it("shows the error of an expired request and reports no tools", async () => { + fetchStub.callsFake(neverAnswer); + const reported: Tool[][] = []; + const el = await fixture( + html` reported.push(e.detail.tools)} + >` + ); + + await waitUntil(() => + el.shadowRoot?.textContent?.includes("Request timed out after 20 ms") + ); + expect(internals(el).tools).to.deep.equal([]); + expect(reported).to.deep.equal([[]]); + }); }); diff --git a/packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts b/packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts index 9352b205..16ee3219 100644 --- a/packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts +++ b/packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { TrsProvider, DescriptorType, @@ -13,16 +18,28 @@ import { * This class combines the functionality of TrsAPI and RestTrsProvider */ export class RestTrsProvider implements TrsProvider { - // eslint-disable-next-line no-useless-constructor - constructor(public readonly baseUrl: string) {} + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the TRS API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor( + public readonly baseUrl: string, + options: RestProviderOptions = {} + ) { + this.timeout = resolveRequestTimeout(options); + } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } async getToolClasses(): Promise { diff --git a/packages/ecc-client-ga4gh-trs/src/providers/tests/rest-trs-provider-timeout.test.ts b/packages/ecc-client-ga4gh-trs/src/providers/tests/rest-trs-provider-timeout.test.ts new file mode 100644 index 00000000..3e1879d6 --- /dev/null +++ b/packages/ecc-client-ga4gh-trs/src/providers/tests/rest-trs-provider-timeout.test.ts @@ -0,0 +1,95 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; +import { RestTrsProvider } from "../rest-trs-provider.js"; + +const BASE_URL = "https://trs.example.org/ga4gh/trs/v2"; + +/** Provider that adds a bearer token to every request, as in the docs. */ +class TokenProvider extends RestTrsProvider { + protected fetch(input: RequestInfo | URL, init: RequestInit = {}) { + const headers = new Headers(init.headers); + headers.set("Authorization", "Bearer test-token"); + return super.fetch(input, { ...init, headers }); + } +} + +/** Provider methods, one of each kind of request. */ +const CALLS: [string, (p: RestTrsProvider) => Promise][] = [ + ["getToolClasses", (p) => p.getToolClasses()], +]; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + +/** The error that a call rejects with. */ +const rejection = async (call: () => Promise): Promise => { + try { + await call(); + } catch (err) { + return err; + } + throw new Error("Expected the call to reject"); +}; + +describe("RestTrsProvider request timeout", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("defaults to 30 s", () => { + expect(new RestTrsProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect(() => new RestTrsProvider(BASE_URL, { timeout: -1 })).to.throw( + RangeError + ); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + const provider = new RestTrsProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => call(provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as Error).message).to.equal( + "Request timed out after 20 ms" + ); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + const provider = new TokenProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => CALLS[0][1](provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + const headers = new Headers(fetchStub.firstCall.args[1]?.headers); + expect(headers.get("Authorization")).to.equal("Bearer test-token"); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("{}", { status: 200 })); + + await CALLS[0][1](new RestTrsProvider(BASE_URL, { timeout: 0 })); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); +}); From c04f48b5eaedf5bbd440d84882f5baa6be71de18 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:54:44 +0100 Subject: [PATCH 07/15] feat(trs-filer): time out REST requests RestTrsFilerProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/trs-filer-request-timeout.md | 5 + .../pages/docs/trs-filer/providers.mdx | 5 +- .../src/providers/rest-trs-filer-provider.ts | 29 ++++-- .../rest-trs-filer-provider-timeout.test.ts | 99 +++++++++++++++++++ 4 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 .changeset/trs-filer-request-timeout.md create mode 100644 packages/ecc-client-elixir-trs-filer/src/providers/tests/rest-trs-filer-provider-timeout.test.ts diff --git a/.changeset/trs-filer-request-timeout.md b/.changeset/trs-filer-request-timeout.md new file mode 100644 index 00000000..3f60717f --- /dev/null +++ b/.changeset/trs-filer-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/trs-filer": minor +--- + +Time out the requests of `RestTrsFilerProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestTrsFilerProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/apps/documentation/pages/docs/trs-filer/providers.mdx b/apps/documentation/pages/docs/trs-filer/providers.mdx index 25bfe64b..1344f6ae 100644 --- a/apps/documentation/pages/docs/trs-filer/providers.mdx +++ b/apps/documentation/pages/docs/trs-filer/providers.mdx @@ -79,11 +79,12 @@ The `RestTrsFilerProvider` is the main implementation that communicates with TRS ### Constructor ```typescript -constructor(baseUrl: string) +constructor(baseUrl: string, options?: { timeout?: number }) ``` **Parameters:** - `baseUrl`: The base URL of the TRS Filer API endpoint (e.g., `https://trs-filer.example.com/ga4gh/trs/v2`) +- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -497,6 +498,8 @@ class CustomTrsFilerProvider extends RestTrsFilerProvider { } ``` +Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `TrsFilerProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). + For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts b/packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts index 60f1f212..dbdd0c72 100644 --- a/packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts +++ b/packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { TrsFilerProvider, DescriptorType, @@ -16,16 +21,28 @@ import { * This class combines the functionality of TrsAPI and RestTrsProvider for TRS-Filer */ export class RestTrsFilerProvider implements TrsFilerProvider { - // eslint-disable-next-line no-useless-constructor - constructor(public readonly baseUrl: string) {} + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the TRS-Filer API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor( + public readonly baseUrl: string, + options: RestProviderOptions = {} + ) { + this.timeout = resolveRequestTimeout(options); + } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } async getToolClasses(): Promise { diff --git a/packages/ecc-client-elixir-trs-filer/src/providers/tests/rest-trs-filer-provider-timeout.test.ts b/packages/ecc-client-elixir-trs-filer/src/providers/tests/rest-trs-filer-provider-timeout.test.ts new file mode 100644 index 00000000..8ce395c6 --- /dev/null +++ b/packages/ecc-client-elixir-trs-filer/src/providers/tests/rest-trs-filer-provider-timeout.test.ts @@ -0,0 +1,99 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; +import { RestTrsFilerProvider } from "../rest-trs-filer-provider.js"; + +const BASE_URL = "https://trs.example.org/ga4gh/trs/v2"; + +/** Provider that adds a bearer token to every request, as in the docs. */ +class TokenProvider extends RestTrsFilerProvider { + protected fetch(input: RequestInfo | URL, init: RequestInit = {}) { + const headers = new Headers(init.headers); + headers.set("Authorization", "Bearer test-token"); + return super.fetch(input, { ...init, headers }); + } +} + +/** Provider methods, one of each kind of request. */ +const CALLS: [string, (p: RestTrsFilerProvider) => Promise][] = [ + ["getToolClasses", (p) => p.getToolClasses()], + [ + "createToolClass", + (p) => p.createToolClass({ name: "Workflow", description: "" }), + ], +]; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + +/** The error that a call rejects with. */ +const rejection = async (call: () => Promise): Promise => { + try { + await call(); + } catch (err) { + return err; + } + throw new Error("Expected the call to reject"); +}; + +describe("RestTrsFilerProvider request timeout", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("defaults to 30 s", () => { + expect(new RestTrsFilerProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect(() => new RestTrsFilerProvider(BASE_URL, { timeout: -1 })).to.throw( + RangeError + ); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + const provider = new RestTrsFilerProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => call(provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as Error).message).to.equal( + "Request timed out after 20 ms" + ); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + const provider = new TokenProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => CALLS[0][1](provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + const headers = new Headers(fetchStub.firstCall.args[1]?.headers); + expect(headers.get("Authorization")).to.equal("Bearer test-token"); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("{}", { status: 200 })); + + await CALLS[0][1](new RestTrsFilerProvider(BASE_URL, { timeout: 0 })); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); +}); From d899b2d1a207a9680c8bfbe86da8c25d632e3362 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:57:22 +0100 Subject: [PATCH 08/15] feat(drs): time out REST requests RestDrsProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/drs-request-timeout.md | 5 + .../objects-list/tests/objects.test.ts | 25 +++++ .../src/providers/rest-drs-provider.ts | 29 ++++-- .../tests/rest-drs-provider-timeout.test.ts | 96 +++++++++++++++++++ 4 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 .changeset/drs-request-timeout.md create mode 100644 packages/ecc-client-ga4gh-drs/src/providers/tests/rest-drs-provider-timeout.test.ts diff --git a/.changeset/drs-request-timeout.md b/.changeset/drs-request-timeout.md new file mode 100644 index 00000000..dab15a3a --- /dev/null +++ b/.changeset/drs-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/drs": minor +--- + +Time out the requests of `RestDrsProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestDrsProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/packages/ecc-client-ga4gh-drs/src/components/objects-list/tests/objects.test.ts b/packages/ecc-client-ga4gh-drs/src/components/objects-list/tests/objects.test.ts index cd654566..411a9755 100644 --- a/packages/ecc-client-ga4gh-drs/src/components/objects-list/tests/objects.test.ts +++ b/packages/ecc-client-ga4gh-drs/src/components/objects-list/tests/objects.test.ts @@ -3,11 +3,18 @@ import { expect, fixture, html, waitUntil } from "@open-wc/testing"; import sinon from "sinon"; import "../index.js"; import type { ECCClientGa4ghDrsObjects } from "../objects.js"; +import { RestDrsProvider } from "../../../providers/rest-drs-provider.js"; import type { DrsObject, DrsProvider, } from "../../../providers/drs-provider.js"; +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + const BASE_URL = "https://drs.example.org/ga4gh/drs/v1"; const OTHER_URL = "https://other.example.org/ga4gh/drs/v1"; const MISSING = "Please provide either a base URL"; @@ -224,4 +231,22 @@ describe("ecc-client-ga4gh-drs-objects provider", () => { expect(el.shadowRoot?.textContent).not.to.contain("Unavailable"); expect(reported).to.deep.equal([]); }); + + it("shows the error of an expired request and reports no objects", async () => { + fetchStub.callsFake(neverAnswer); + const reported: DrsObject[][] = []; + const el = await fixture( + html` + reported.push(e.detail.objects)} + >` + ); + + await waitUntil(() => + el.shadowRoot?.textContent?.includes("Request timed out after 20 ms") + ); + expect(internals(el).objects).to.deep.equal([]); + expect(reported).to.deep.equal([[]]); + }); }); diff --git a/packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts b/packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts index 975eb18a..20715202 100644 --- a/packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts +++ b/packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { DrsProvider, DrsObject, AccessURL, Service } from "./drs-provider.js"; /** @@ -5,16 +10,28 @@ import { DrsProvider, DrsObject, AccessURL, Service } from "./drs-provider.js"; * This class provides standard GA4GH DRS API functionality */ export class RestDrsProvider implements DrsProvider { - // eslint-disable-next-line no-useless-constructor - constructor(public readonly baseUrl: string) {} + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * @param baseUrl Base URL of the DRS API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor( + public readonly baseUrl: string, + options: RestProviderOptions = {} + ) { + this.timeout = resolveRequestTimeout(options); + } + + /** + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } async getObjects( diff --git a/packages/ecc-client-ga4gh-drs/src/providers/tests/rest-drs-provider-timeout.test.ts b/packages/ecc-client-ga4gh-drs/src/providers/tests/rest-drs-provider-timeout.test.ts new file mode 100644 index 00000000..229e1d82 --- /dev/null +++ b/packages/ecc-client-ga4gh-drs/src/providers/tests/rest-drs-provider-timeout.test.ts @@ -0,0 +1,96 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { expect } from "@open-wc/testing"; +import sinon from "sinon"; +import { + DEFAULT_REQUEST_TIMEOUT, + RequestTimeoutError, +} from "@elixir-cloud/design/utils"; +import { RestDrsProvider } from "../rest-drs-provider.js"; + +const BASE_URL = "https://drs.example.org/ga4gh/drs/v1"; + +/** Provider that adds a bearer token to every request, as in the docs. */ +class TokenProvider extends RestDrsProvider { + protected fetch(input: RequestInfo | URL, init: RequestInit = {}) { + const headers = new Headers(init.headers); + headers.set("Authorization", "Bearer test-token"); + return super.fetch(input, { ...init, headers }); + } +} + +/** Provider methods, one of each kind of request. */ +const CALLS: [string, (p: RestDrsProvider) => Promise][] = [ + ["getServiceInfo", (p) => p.getServiceInfo()], + ["getObject", (p) => p.getObject("object-1")], +]; + +/** A `fetch` that settles only when its signal aborts, like a silent server. */ +const neverAnswer = (_input: RequestInfo | URL, init: RequestInit = {}) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => reject(init.signal?.reason)); + }); + +/** The error that a call rejects with. */ +const rejection = async (call: () => Promise): Promise => { + try { + await call(); + } catch (err) { + return err; + } + throw new Error("Expected the call to reject"); +}; + +describe("RestDrsProvider request timeout", () => { + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, "fetch").callsFake(neverAnswer); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("defaults to 30 s", () => { + expect(new RestDrsProvider(BASE_URL).timeout).to.equal( + DEFAULT_REQUEST_TIMEOUT + ); + }); + + it("rejects an invalid timeout", () => { + expect(() => new RestDrsProvider(BASE_URL, { timeout: -1 })).to.throw( + RangeError + ); + }); + + CALLS.forEach(([name, call]) => { + it(`${name} rejects when the server doesn't answer in time`, async () => { + const provider = new RestDrsProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => call(provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + expect((error as Error).message).to.equal( + "Request timed out after 20 ms" + ); + }); + }); + + it("keeps the timeout with an overridden fetch", async () => { + const provider = new TokenProvider(BASE_URL, { timeout: 20 }); + + const error = await rejection(() => CALLS[0][1](provider)); + + expect(error).to.be.instanceOf(RequestTimeoutError); + const headers = new Headers(fetchStub.firstCall.args[1]?.headers); + expect(headers.get("Authorization")).to.equal("Bearer test-token"); + }); + + it("sends requests without a deadline with a timeout of 0", async () => { + fetchStub.callsFake(async () => new Response("{}", { status: 200 })); + + await CALLS[0][1](new RestDrsProvider(BASE_URL, { timeout: 0 })); + + expect(fetchStub.firstCall.args[1]?.signal).to.equal(undefined); + }); +}); From eb46d08de36b771fe477b51435b261badefe9365 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 10:58:59 +0100 Subject: [PATCH 09/15] feat(drs-filer): time out REST requests RestDrsFilerProvider takes an options argument with timeout (milliseconds, default 30 s, 0 for none) and sends every request with fetchWithTimeout(), so a server that never answers makes the request reject with a RequestTimeoutError and the components show an error instead of loading forever. Overrides of fetch() that call super.fetch() keep the deadline. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .changeset/drs-filer-request-timeout.md | 5 ++++ .../src/providers/rest-drs-filer-provider.ts | 29 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .changeset/drs-filer-request-timeout.md diff --git a/.changeset/drs-filer-request-timeout.md b/.changeset/drs-filer-request-timeout.md new file mode 100644 index 00000000..2e208228 --- /dev/null +++ b/.changeset/drs-filer-request-timeout.md @@ -0,0 +1,5 @@ +--- +"@elixir-cloud/drs-filer": minor +--- + +Time out the requests of `RestDrsFilerProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestDrsFilerProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. diff --git a/packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts b/packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts index 49cf3461..c6652467 100644 --- a/packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts +++ b/packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts @@ -1,3 +1,8 @@ +import { + fetchWithTimeout, + resolveRequestTimeout, +} from "@elixir-cloud/design/utils"; +import type { RestProviderOptions } from "@elixir-cloud/design/utils"; import { DrsFilerProvider, DrsObject, @@ -12,16 +17,28 @@ import { * This class provides DRS-Filer specific functionality for object management */ export class RestDrsFilerProvider implements DrsFilerProvider { - // eslint-disable-next-line no-useless-constructor - constructor(public readonly baseUrl: string) {} + /** Deadline of each request in milliseconds, `0` for none. */ + public readonly timeout: number; + + /** + * @param baseUrl Base URL of the DRS-Filer API + * @param options `timeout`: deadline of each request in milliseconds + * (default 30 s, `0` for none) + */ + constructor( + public readonly baseUrl: string, + options: RestProviderOptions = {} + ) { + this.timeout = resolveRequestTimeout(options); + } /** - * Sends every request of this provider. Override it in a subclass to add - * headers (e.g. `Authorization`) or otherwise change requests. + * Sends every request of this provider, with the provider's deadline. + * Override it in a subclass to add headers (e.g. `Authorization`) or + * otherwise change requests; call `super.fetch()` to keep the deadline. */ - // eslint-disable-next-line class-methods-use-this protected fetch(input: RequestInfo | URL, init?: RequestInit) { - return fetch(input, init); + return fetchWithTimeout(input, init, this.timeout); } // Base DRS operations (inherited from DrsProvider) From 07816fe6d63067649fbccdcda50b74b7d37852fd Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 11:00:26 +0100 Subject: [PATCH 10/15] docs: describe request timeouts of providers Add a Timeouts section to the providers overview: the default deadline of the REST providers, the timeout option, and that custom providers should reject rather than stay pending. Refs #599 Co-Authored-By: Claude Opus 5.5 --- apps/documentation/pages/docs/providers.mdx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/documentation/pages/docs/providers.mdx b/apps/documentation/pages/docs/providers.mdx index e34ca458..be85b3da 100644 --- a/apps/documentation/pages/docs/providers.mdx +++ b/apps/documentation/pages/docs/providers.mdx @@ -311,6 +311,20 @@ const RetryableProvider = withRetry(RestWesProvider, 3, 1000); const provider = new RetryableProvider('https://api.example.com'); ``` +Each attempt through `super.fetch()` gets the provider's own request deadline (see below). + +#### Timeouts + +The REST providers give every request a deadline, 30 seconds by default, so that a server that never answers makes the request reject with a `RequestTimeoutError` instead of leaving the components loading. Set it with the `timeout` option (milliseconds, `0` for none): + +```tsx copy +const provider = new RestWesProvider('https://api.example.com', { + timeout: 10_000, +}); +``` + +Custom providers that don't extend a REST provider should reject, not stay pending, when a request can't complete. See [Request timeouts](/docs/design/request-timeouts). + ### Caching and Performance #### Request Caching From 209acb202a35cdb065eadafb98f8c9038be875f6 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 11:26:29 +0100 Subject: [PATCH 11/15] fix(design): harden request timeouts From the review of the branch: - Unref the deadline timer, so that it doesn't keep Node processes (SSR, tests) alive after a request. - Stop following the caller's signal once the deadline expires, so a long-lived signal doesn't collect listeners. - Reject with the RequestTimeoutError also where fetch rejects with a plain AbortError instead of the abort reason. - Say why the timer isn't cleared when the response arrives. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .../src/utils/request-timeout.test.ts | 43 +++++++++++++++++++ .../src/utils/request-timeout.ts | 39 ++++++++++------- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/packages/ecc-utils-design/src/utils/request-timeout.test.ts b/packages/ecc-utils-design/src/utils/request-timeout.test.ts index 0401923c..22cb7707 100644 --- a/packages/ecc-utils-design/src/utils/request-timeout.test.ts +++ b/packages/ecc-utils-design/src/utils/request-timeout.test.ts @@ -181,4 +181,47 @@ describe("fetchWithTimeout()", () => { expect(((await request) as Error).message).to.equal("cancelled"); }); + + it("rejects with the timeout error for a plain AbortError", async () => { + // Like fetch implementations that ignore the abort reason + fetchStub.callsFake( + (_input, init: RequestInit) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => + reject(new DOMException("Aborted", "AbortError")) + ); + }) + ); + + const error = await rejectionOf( + fetchWithTimeout("https://api.example.org/things", {}, 20) + ); + + expect(error).to.be.instanceOf(RequestTimeoutError); + }); + + it("passes other errors on", async () => { + fetchStub.rejects(new TypeError("Failed to fetch")); + + const error = await rejectionOf( + fetchWithTimeout("https://api.example.org/things", {}, 1000) + ); + + expect(error).to.be.instanceOf(TypeError); + }); + + it("stops following the caller's signal once the deadline expires", async () => { + const caller = new AbortController(); + const removed = sinon.spy(caller.signal, "removeEventListener"); + + await rejectionOf( + fetchWithTimeout( + "https://api.example.org/things", + { signal: caller.signal }, + 20 + ) + ); + + expect(removed.calledWith("abort")).to.equal(true); + }); }); diff --git a/packages/ecc-utils-design/src/utils/request-timeout.ts b/packages/ecc-utils-design/src/utils/request-timeout.ts index 1adb8c14..d782fef0 100644 --- a/packages/ecc-utils-design/src/utils/request-timeout.ts +++ b/packages/ecc-utils-design/src/utils/request-timeout.ts @@ -96,24 +96,33 @@ export function fetchWithTimeout( return fetch(request, init); } const controller = new AbortController() as AbortControllerWithReason; - const timer = setTimeout( - () => controller.abort(new RequestTimeoutError(timeout)), - timeout - ); const signal = (init.signal ?? (input instanceof Request ? input.signal : undefined)) as | AbortSignalWithReason | undefined; - if (signal) { - const abort = () => { - clearTimeout(timer); - controller.abort(signal.reason); - }; - if (signal.aborted) { - abort(); - } else { - signal.addEventListener("abort", abort, { once: true }); - } + // Deliberately not cleared when the response arrives, so that the + // deadline also covers reading the body; aborting afterwards is a no-op + const timer = setTimeout(() => { + signal?.removeEventListener("abort", followSignal); + controller.abort(new RequestTimeoutError(timeout)); + }, timeout); + // Don't keep Node processes (SSR, tests) alive for the deadline + (timer as { unref?: () => void }).unref?.(); + function followSignal() { + clearTimeout(timer); + controller.abort(signal?.reason); + } + if (signal?.aborted) { + followSignal(); + } else { + signal?.addEventListener("abort", followSignal, { once: true }); } - return fetch(request, { ...init, signal: controller.signal }); + return fetch(request, { ...init, signal: controller.signal }).catch( + (error: unknown) => { + // Fetch implementations that reject with a plain `AbortError` + // instead of the abort reason still reject with the timeout error + const { reason } = controller.signal; + throw reason instanceof RequestTimeoutError ? reason : error; + } + ); } From c1e717b7264b40b1d51224d16bcb8709f1013b73 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 11:28:29 +0100 Subject: [PATCH 12/15] docs: clarify request timeouts of providers - Warn that a timed-out create request may still have succeeded, and that such requests shouldn't be retried automatically. - Say that the deadline applies per attempt in the retry example. - Show the constructors of the DRS and DRS-Filer providers, which have no providers page. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .../pages/docs/design/request-timeouts.mdx | 15 ++++++++++++++- apps/documentation/pages/docs/providers.mdx | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/documentation/pages/docs/design/request-timeouts.mdx b/apps/documentation/pages/docs/design/request-timeouts.mdx index 5b81f883..14c1a555 100644 --- a/apps/documentation/pages/docs/design/request-timeouts.mdx +++ b/apps/documentation/pages/docs/design/request-timeouts.mdx @@ -31,7 +31,13 @@ The REST providers of these packages have the option: [Service Registry](/docs/service-registry/providers), [TES](/docs/tes/providers), [WES](/docs/wes/providers), [TRS](/docs/trs/providers), [TRS-Filer](/docs/trs-filer/providers), DRS -(`RestDrsProvider`) and DRS-Filer (`RestDrsFilerProvider`). +and DRS-Filer. DRS and DRS-Filer have no providers page yet; their +constructors take the same option: + +```ts +new RestDrsProvider(baseUrl: string, options?: { timeout?: number }) +new RestDrsFilerProvider(baseUrl: string, options?: { timeout?: number }) +``` A provider that overrides `fetch()` and calls `super.fetch()` (e.g. to add an `Authorization` @@ -46,6 +52,13 @@ The REST providers of these packages have the option: `@elixir-cloud/design/utils` (below) does this for `fetch`. + + A timed-out request that creates something (e.g. `createTask()` of TES, `runWorkflow()` of WES, + the create methods of TRS-Filer and DRS-Filer) may still have succeeded on the server: the client + only stops waiting. Check before submitting again, and don't retry such requests automatically on + a timeout. Raise the deadline for slow uploads, e.g. large workflow attachments. + + ## Utilities `@elixir-cloud/design/utils` (which registers no components) exports what diff --git a/apps/documentation/pages/docs/providers.mdx b/apps/documentation/pages/docs/providers.mdx index be85b3da..d81e4c57 100644 --- a/apps/documentation/pages/docs/providers.mdx +++ b/apps/documentation/pages/docs/providers.mdx @@ -311,7 +311,7 @@ const RetryableProvider = withRetry(RestWesProvider, 3, 1000); const provider = new RetryableProvider('https://api.example.com'); ``` -Each attempt through `super.fetch()` gets the provider's own request deadline (see below). +The provider's request deadline (see [Timeouts](#timeouts)) applies to each attempt through `super.fetch()`, not to the retried call as a whole: that can take up to the number of attempts times the deadline, plus the delays. Retry only requests that are safe to repeat: a timed-out request that creates something may still have succeeded on the server. #### Timeouts From 11984e80d323b3a810ef3a9a6a76b899abafd4ee Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 11:37:36 +0100 Subject: [PATCH 13/15] fix(design): keep timeout error without reasons Keep the RequestTimeoutError in a variable, so that a plain AbortError from fetch maps to it also in browsers whose signals drop the abort reason. Say that reading the body rejects with an AbortError there. Refs #599 Co-Authored-By: Claude Opus 5.5 --- .../pages/docs/design/request-timeouts.mdx | 3 ++- .../src/utils/request-timeout.test.ts | 24 +++++++++++++++++++ .../src/utils/request-timeout.ts | 14 +++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/documentation/pages/docs/design/request-timeouts.mdx b/apps/documentation/pages/docs/design/request-timeouts.mdx index 14c1a555..a6500a30 100644 --- a/apps/documentation/pages/docs/design/request-timeouts.mdx +++ b/apps/documentation/pages/docs/design/request-timeouts.mdx @@ -11,7 +11,8 @@ ms`); components show it like any other error and fire their events as on a failure (lists, for example, their `ecc-*-changed` event with empty data). The deadline covers the whole request, from sending it until its response -body has been read. It is **30 seconds** by default, set per provider with the +body has been read (if it expires while the body is read, browsers without +abort reasons reject with an `AbortError` instead). It is **30 seconds** by default, set per provider with the `timeout` option (in milliseconds; `0` for none): ```ts diff --git a/packages/ecc-utils-design/src/utils/request-timeout.test.ts b/packages/ecc-utils-design/src/utils/request-timeout.test.ts index 22cb7707..d9377f1b 100644 --- a/packages/ecc-utils-design/src/utils/request-timeout.test.ts +++ b/packages/ecc-utils-design/src/utils/request-timeout.test.ts @@ -200,6 +200,30 @@ describe("fetchWithTimeout()", () => { expect(error).to.be.instanceOf(RequestTimeoutError); }); + it("rejects with the timeout error where signals drop the abort reason", async () => { + // Like browsers without abort reasons: `abort()` ignores its argument + const { abort } = AbortController.prototype; + sinon + .stub(AbortController.prototype, "abort") + .callsFake(function abortWithoutReason(this: AbortController) { + abort.call(this); + }); + fetchStub.callsFake( + (_input, init: RequestInit) => + new Promise((_resolve, reject) => { + init.signal?.addEventListener("abort", () => + reject(new DOMException("Aborted", "AbortError")) + ); + }) + ); + + const error = await rejectionOf( + fetchWithTimeout("https://api.example.org/things", {}, 20) + ); + + expect(error).to.be.instanceOf(RequestTimeoutError); + }); + it("passes other errors on", async () => { fetchStub.rejects(new TypeError("Failed to fetch")); diff --git a/packages/ecc-utils-design/src/utils/request-timeout.ts b/packages/ecc-utils-design/src/utils/request-timeout.ts index d782fef0..442567d7 100644 --- a/packages/ecc-utils-design/src/utils/request-timeout.ts +++ b/packages/ecc-utils-design/src/utils/request-timeout.ts @@ -6,7 +6,8 @@ * * The deadline covers the whole request: from sending it until its response * body has been read (`response.json()` and the like reject too once it has - * expired). + * expired, with the `RequestTimeoutError` in browsers that support abort + * reasons, else with an `AbortError`). */ /** `AbortSignal` with its abort reason (newer than TypeScript 4.3's DOM). */ @@ -102,11 +103,15 @@ export function fetchWithTimeout( | undefined; // Deliberately not cleared when the response arrives, so that the // deadline also covers reading the body; aborting afterwards is a no-op + // Kept here too, as browsers without abort reasons drop it from the signal + let timeoutError: RequestTimeoutError | undefined; const timer = setTimeout(() => { signal?.removeEventListener("abort", followSignal); - controller.abort(new RequestTimeoutError(timeout)); + timeoutError = new RequestTimeoutError(timeout); + controller.abort(timeoutError); }, timeout); - // Don't keep Node processes (SSR, tests) alive for the deadline + // Don't keep Node processes (SSR, tests) alive for the deadline; the cast + // is for Node's timer object (in browsers, timers are numbers) (timer as { unref?: () => void }).unref?.(); function followSignal() { clearTimeout(timer); @@ -121,8 +126,7 @@ export function fetchWithTimeout( (error: unknown) => { // Fetch implementations that reject with a plain `AbortError` // instead of the abort reason still reject with the timeout error - const { reason } = controller.signal; - throw reason instanceof RequestTimeoutError ? reason : error; + throw timeoutError ?? error; } ); } From e58aa0da22e8d28678cb57c99387b2c224f6e016 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Wed, 18 Nov 2026 12:17:03 +0100 Subject: [PATCH 14/15] fix(design): follow request signals like fetch From the automated review: - Read the signal of a Request without instanceof, so that requests of other realms (iframes) are followed too. - Let a signal in init replace the Request's even when it is null, as fetch does. - Release the timer and the caller's signal when fetch rejects. - Don't repeat timed-out requests other than GET and HEAD in the retry example of the providers docs. Refs #599 Co-Authored-By: Claude Opus 5.5 --- apps/documentation/pages/docs/providers.mdx | 12 +++++ .../src/utils/request-timeout.test.ts | 51 +++++++++++++++++++ .../src/utils/request-timeout.ts | 15 ++++-- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/apps/documentation/pages/docs/providers.mdx b/apps/documentation/pages/docs/providers.mdx index d81e4c57..b860c5ba 100644 --- a/apps/documentation/pages/docs/providers.mdx +++ b/apps/documentation/pages/docs/providers.mdx @@ -278,6 +278,8 @@ function handleProviderError(error, method, args) { #### Retry Logic ```tsx copy +import { RequestTimeoutError } from '@elixir-cloud/design/utils'; + // Retry wrapper for transient failures function withRetry(Provider, maxRetries = 3, delay = 1000) { return class extends Provider { @@ -294,6 +296,16 @@ function withRetry(Provider, maxRetries = 3, delay = 1000) { if (error.status >= 400 && error.status < 500) { throw error; } + + // Don't repeat a timed-out request that may have changed + // something: the server may have done it already + const method = (options.method ?? 'GET').toUpperCase(); + if ( + error instanceof RequestTimeoutError && + !['GET', 'HEAD'].includes(method) + ) { + throw error; + } if (i < maxRetries) { await new Promise(resolve => setTimeout(resolve, delay * (i + 1))); diff --git a/packages/ecc-utils-design/src/utils/request-timeout.test.ts b/packages/ecc-utils-design/src/utils/request-timeout.test.ts index d9377f1b..08d39a3c 100644 --- a/packages/ecc-utils-design/src/utils/request-timeout.test.ts +++ b/packages/ecc-utils-design/src/utils/request-timeout.test.ts @@ -224,6 +224,57 @@ describe("fetchWithTimeout()", () => { expect(error).to.be.instanceOf(RequestTimeoutError); }); + it("follows the signal of a Request-like input of another realm", async () => { + const caller = new AbortController(); + // Not an instance of this realm's Request, as from an iframe + const input = { + url: "https://api.example.org/things", + signal: caller.signal, + } as unknown as Request; + const request = rejectionOf(fetchWithTimeout(input, {}, 1000)); + + caller.abort(new Error("cancelled")); + + expect(((await request) as Error).message).to.equal("cancelled"); + }); + + it("ignores the signal of a Request for a signal of null", async () => { + const caller = new AbortController(); + caller.abort(new Error("cancelled")); + fetchStub.callsFake(async (_input, init: RequestInit) => { + if (init.signal?.aborted) { + throw init.signal.reason; + } + return new Response("ok"); + }); + + const response = await fetchWithTimeout( + new Request("https://api.example.org/things", { signal: caller.signal }), + { signal: null }, + 1000 + ); + + expect(await response.text()).to.equal("ok"); + }); + + it("releases the timer and the caller's signal when fetch fails", async () => { + const caller = new AbortController(); + const removed = sinon.spy(caller.signal, "removeEventListener"); + const cleared = sinon.spy(window, "clearTimeout"); + fetchStub.rejects(new TypeError("Failed to fetch")); + + await rejectionOf( + fetchWithTimeout( + "https://api.example.org/things", + { signal: caller.signal }, + 1000 + ) + ); + + expect(removed.calledWith("abort")).to.equal(true); + expect(cleared.called).to.equal(true); + }); + it("passes other errors on", async () => { fetchStub.rejects(new TypeError("Failed to fetch")); diff --git a/packages/ecc-utils-design/src/utils/request-timeout.ts b/packages/ecc-utils-design/src/utils/request-timeout.ts index 442567d7..e7d0cc83 100644 --- a/packages/ecc-utils-design/src/utils/request-timeout.ts +++ b/packages/ecc-utils-design/src/utils/request-timeout.ts @@ -97,14 +97,18 @@ export function fetchWithTimeout( return fetch(request, init); } const controller = new AbortController() as AbortControllerWithReason; - const signal = (init.signal ?? - (input instanceof Request ? input.signal : undefined)) as + // As in `fetch`, a `signal` in `init` (even `null`) replaces the one of a + // `Request`; read without `instanceof`, which misses other realms' requests + const requestSignal = + typeof input === "object" && "signal" in input ? input.signal : undefined; + const signal = ("signal" in init ? init.signal : requestSignal) as | AbortSignalWithReason + | null | undefined; - // Deliberately not cleared when the response arrives, so that the - // deadline also covers reading the body; aborting afterwards is a no-op // Kept here too, as browsers without abort reasons drop it from the signal let timeoutError: RequestTimeoutError | undefined; + // Deliberately not cleared when the response arrives, so that the + // deadline also covers reading the body; aborting afterwards is a no-op const timer = setTimeout(() => { signal?.removeEventListener("abort", followSignal); timeoutError = new RequestTimeoutError(timeout); @@ -124,6 +128,9 @@ export function fetchWithTimeout( } return fetch(request, { ...init, signal: controller.signal }).catch( (error: unknown) => { + // The request is over: release the timer and the caller's signal + clearTimeout(timer); + signal?.removeEventListener("abort", followSignal); // Fetch implementations that reject with a plain `AbortError` // instead of the abort reason still reject with the timeout error throw timeoutError ?? error; From 643a480d89433193eaceef8b619842ee5df87efa Mon Sep 17 00:00:00 2001 From: Anurag Gupta Date: Mon, 23 Nov 2026 12:57:00 +0530 Subject: [PATCH 15/15] docs: trim request timeout docs and changesets --- .changeset/cloud-registry-request-timeout.md | 2 +- .changeset/design-request-timeout.md | 2 +- .changeset/drs-filer-request-timeout.md | 2 +- .changeset/drs-request-timeout.md | 2 +- .../service-registry-request-timeout.md | 2 +- .changeset/tes-request-timeout.md | 2 +- .changeset/trs-filer-request-timeout.md | 2 +- .changeset/trs-request-timeout.md | 2 +- .changeset/wes-request-timeout.md | 2 +- .../pages/docs/cloud-registry/providers.mdx | 4 +- .../pages/docs/design/request-timeouts.mdx | 79 ++++++------------- apps/documentation/pages/docs/providers.mdx | 6 +- .../pages/docs/service-registry/providers.mdx | 4 +- .../pages/docs/tes/providers.mdx | 4 +- .../pages/docs/trs-filer/providers.mdx | 4 +- .../pages/docs/trs/providers.mdx | 4 +- .../pages/docs/wes/providers.mdx | 4 +- 17 files changed, 43 insertions(+), 84 deletions(-) diff --git a/.changeset/cloud-registry-request-timeout.md b/.changeset/cloud-registry-request-timeout.md index abb60195..bc8c7a39 100644 --- a/.changeset/cloud-registry-request-timeout.md +++ b/.changeset/cloud-registry-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/cloud-registry": minor --- -Time out the requests of `RestCloudRegistryProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestCloudRegistryProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestCloudRegistryProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/design-request-timeout.md b/.changeset/design-request-timeout.md index 089731d2..8d49bec9 100644 --- a/.changeset/design-request-timeout.md +++ b/.changeset/design-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/design": minor --- -Add request deadlines for the REST providers of the client packages to `@elixir-cloud/design/utils`: `fetchWithTimeout()` sends a request with `fetch` and aborts it with a `RequestTimeoutError` once its deadline expires (default `DEFAULT_REQUEST_TIMEOUT`, 30 s; `0` for none), and `resolveRequestTimeout()` reads the deadline of provider options (`RestProviderOptions`, `{ timeout?: number }`). +Add `fetchWithTimeout()`, `RequestTimeoutError` and the other request timeout utilities to `@elixir-cloud/design/utils`. diff --git a/.changeset/drs-filer-request-timeout.md b/.changeset/drs-filer-request-timeout.md index 2e208228..5cb6ddad 100644 --- a/.changeset/drs-filer-request-timeout.md +++ b/.changeset/drs-filer-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/drs-filer": minor --- -Time out the requests of `RestDrsFilerProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestDrsFilerProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestDrsFilerProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/drs-request-timeout.md b/.changeset/drs-request-timeout.md index dab15a3a..2a6d433e 100644 --- a/.changeset/drs-request-timeout.md +++ b/.changeset/drs-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/drs": minor --- -Time out the requests of `RestDrsProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestDrsProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestDrsProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/service-registry-request-timeout.md b/.changeset/service-registry-request-timeout.md index 4a87b585..e3ab1a6c 100644 --- a/.changeset/service-registry-request-timeout.md +++ b/.changeset/service-registry-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/service-registry": minor --- -Time out the requests of `RestServiceRegistryProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestServiceRegistryProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestServiceRegistryProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/tes-request-timeout.md b/.changeset/tes-request-timeout.md index 33c43bab..4b3f7e66 100644 --- a/.changeset/tes-request-timeout.md +++ b/.changeset/tes-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/tes": minor --- -Time out the requests of `RestTesProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestTesProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestTesProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/trs-filer-request-timeout.md b/.changeset/trs-filer-request-timeout.md index 3f60717f..36e5bf55 100644 --- a/.changeset/trs-filer-request-timeout.md +++ b/.changeset/trs-filer-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/trs-filer": minor --- -Time out the requests of `RestTrsFilerProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestTrsFilerProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestTrsFilerProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/trs-request-timeout.md b/.changeset/trs-request-timeout.md index b86dceae..74c9f27c 100644 --- a/.changeset/trs-request-timeout.md +++ b/.changeset/trs-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/trs": minor --- -Time out the requests of `RestTrsProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestTrsProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. +`RestTrsProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/.changeset/wes-request-timeout.md b/.changeset/wes-request-timeout.md index fab8d72a..2add92d4 100644 --- a/.changeset/wes-request-timeout.md +++ b/.changeset/wes-request-timeout.md @@ -2,4 +2,4 @@ "@elixir-cloud/wes": minor --- -Time out the requests of `RestWesProvider`: each request rejects with a `RequestTimeoutError` (of `@elixir-cloud/design/utils`) once its deadline expires, 30 s by default, so that the components show an error instead of loading forever when a server never answers. Set the deadline with the new constructor option `timeout` (milliseconds, `0` for none): `new RestWesProvider(baseUrl, { timeout: 10_000 })`. Subclasses that override `fetch()` and call `super.fetch()` keep it. The deadline includes uploading the attachments of `runWorkflow()`: raise it for large attachments. +`RestWesProvider` times out requests after 30 s by default. Set another deadline with the new `timeout` option (milliseconds, `0` for none). diff --git a/apps/documentation/pages/docs/cloud-registry/providers.mdx b/apps/documentation/pages/docs/cloud-registry/providers.mdx index 63d00edf..fb0cca48 100644 --- a/apps/documentation/pages/docs/cloud-registry/providers.mdx +++ b/apps/documentation/pages/docs/cloud-registry/providers.mdx @@ -54,7 +54,7 @@ constructor(baseUrl: string, options?: { timeout?: number }) **Parameters:** - `baseUrl`: The base URL of the Cloud Registry API endpoint (e.g., `https://cloud-registry.example.com/ga4gh/registry/v1`) -- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). +- `options.timeout`: request deadline in milliseconds (default 30 s, `0` for none). See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -427,8 +427,6 @@ class CustomCloudRegistryProvider extends RestCloudRegistryProvider { } ``` -Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `CloudRegistryProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). - For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/apps/documentation/pages/docs/design/request-timeouts.mdx b/apps/documentation/pages/docs/design/request-timeouts.mdx index a6500a30..29709f43 100644 --- a/apps/documentation/pages/docs/design/request-timeouts.mdx +++ b/apps/documentation/pages/docs/design/request-timeouts.mdx @@ -2,77 +2,48 @@ import { Callout } from 'nextra/components'; # Request timeouts -The REST providers of the client packages give every request a deadline, so -that a request that never settles (e.g. to a server that accepts the -connection but never answers) fails instead of leaving a component loading -forever. Once the deadline expires, the request is aborted and its promise -rejects with a `RequestTimeoutError` (message `Request timed out after 30000 -ms`); components show it like any other error and fire their events as on a -failure (lists, for example, their `ecc-*-changed` event with empty data). +Every request of a REST provider has a deadline, so that a server that never +answers makes the component show an error instead of loading forever. When +the deadline expires, the request rejects with a `RequestTimeoutError`. -The deadline covers the whole request, from sending it until its response -body has been read (if it expires while the body is read, browsers without -abort reasons reject with an `AbortError` instead). It is **30 seconds** by default, set per provider with the -`timeout` option (in milliseconds; `0` for none): +The deadline is **30 seconds** by default and covers the whole request, +including reading the response. Set it per provider with the `timeout` option +(milliseconds, `0` for none): ```ts import { RestTrsProvider } from '@elixir-cloud/trs/providers'; -// 10 s for each request const provider = new RestTrsProvider('https://trs.example.org/ga4gh/trs/v2', { timeout: 10_000, }); ``` -Components that create their REST provider from `baseUrl` use the default. -To set another deadline, pass them a provider instead. +All REST providers take this option, including `RestDrsProvider` and +`RestDrsFilerProvider`. Components created with `baseUrl` use the default; to +set another deadline, pass them a provider. -The REST providers of these packages have the option: -[Cloud Registry](/docs/cloud-registry/providers), -[Service Registry](/docs/service-registry/providers), -[TES](/docs/tes/providers), [WES](/docs/wes/providers), -[TRS](/docs/trs/providers), [TRS-Filer](/docs/trs-filer/providers), DRS -and DRS-Filer. DRS and DRS-Filer have no providers page yet; their -constructors take the same option: - -```ts -new RestDrsProvider(baseUrl: string, options?: { timeout?: number }) -new RestDrsFilerProvider(baseUrl: string, options?: { timeout?: number }) -``` - - - A provider that overrides `fetch()` and calls `super.fetch()` (e.g. to add an `Authorization` - header) keeps the deadline. A `signal` passed in the request options still aborts the request, - with its own reason. - - - - Custom providers that implement a provider interface without extending a REST provider set their - own deadlines. Their methods should reject, not stay pending, when a request can't complete: a - promise that never settles leaves the component loading. `fetchWithTimeout()` of - `@elixir-cloud/design/utils` (below) does this for `fetch`. - +A provider that overrides `fetch()` and calls `super.fetch()` keeps the +deadline. A custom provider that doesn't extend a REST provider must set its +own: its methods should reject, not stay pending. - A timed-out request that creates something (e.g. `createTask()` of TES, `runWorkflow()` of WES, - the create methods of TRS-Filer and DRS-Filer) may still have succeeded on the server: the client - only stops waiting. Check before submitting again, and don't retry such requests automatically on - a timeout. Raise the deadline for slow uploads, e.g. large workflow attachments. + A timed-out request that creates something (e.g. `createTask()` of TES, + `runWorkflow()` of WES) may still have succeeded on the server. Don't retry + it automatically. ## Utilities -`@elixir-cloud/design/utils` (which registers no components) exports what -the REST providers use: +`@elixir-cloud/design/utils` exports what the REST providers use: -| Export | Description | -| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `fetchWithTimeout(input, init?, timeout?)` | `fetch` with a deadline in milliseconds (default 30 s, `0` for none); aborts with a `RequestTimeoutError` once it expires. A `signal` in `init` or of a `Request` still aborts with its own reason. | -| `RequestTimeoutError` | The error of an expired request, with `name` `RequestTimeoutError` and the deadline as `timeout`. | -| `resolveRequestTimeout(options?)` | The deadline of provider options (`{ timeout?: number }`): the default if unset; throws a `RangeError` unless it is an integer from `0` to `MAX_REQUEST_TIMEOUT`. | -| `DEFAULT_REQUEST_TIMEOUT` | `30000` (30 s). | -| `MAX_REQUEST_TIMEOUT` | `2147483647` (about 24.8 days), the longest deadline timers support. | -| `RestProviderOptions` | Type of the options (`{ timeout?: number }`). | +| Export | Description | +| ------------------------------------------ | ------------------------------------------------------------------------------------ | +| `fetchWithTimeout(input, init?, timeout?)` | `fetch` with a deadline in milliseconds (default 30 s, `0` for none). | +| `RequestTimeoutError` | The error of an expired request, with the deadline as `timeout`. | +| `resolveRequestTimeout(options?)` | The deadline of provider options; throws a `RangeError` for an invalid value. | +| `DEFAULT_REQUEST_TIMEOUT` | `30000` (30 s). | +| `MAX_REQUEST_TIMEOUT` | `2147483647`, the longest deadline that timers support. | +| `RestProviderOptions` | Type of the options (`{ timeout?: number }`). | ```ts import { RequestTimeoutError } from '@elixir-cloud/design/utils'; @@ -81,7 +52,7 @@ try { await provider.getServiceInfo(); } catch (error) { if (error instanceof RequestTimeoutError) { - // The server didn't answer within error.timeout ms + // the server didn't answer within error.timeout ms } } ``` diff --git a/apps/documentation/pages/docs/providers.mdx b/apps/documentation/pages/docs/providers.mdx index 6112eb90..4621d81e 100644 --- a/apps/documentation/pages/docs/providers.mdx +++ b/apps/documentation/pages/docs/providers.mdx @@ -325,11 +325,11 @@ const RetryableProvider = withRetry(RestWesProvider, 3, 1000); const provider = new RetryableProvider('https://api.example.com'); ``` -The provider's request deadline (see [Timeouts](#timeouts)) applies to each attempt through `super.fetch()`, not to the retried call as a whole: that can take up to the number of attempts times the deadline, plus the delays. Retry only requests that are safe to repeat: a timed-out request that creates something may still have succeeded on the server. +Each attempt has its own [deadline](#timeouts). Don't retry a timed-out request that creates something: the server may already have done it. #### Timeouts -The REST providers give every request a deadline, 30 seconds by default, so that a server that never answers makes the request reject with a `RequestTimeoutError` instead of leaving the components loading. Set it with the `timeout` option (milliseconds, `0` for none): +Requests of the REST providers time out after 30 seconds with a `RequestTimeoutError`. Set another deadline with the `timeout` option (milliseconds, `0` for none): ```tsx copy const provider = new RestWesProvider('https://api.example.com', { @@ -337,7 +337,7 @@ const provider = new RestWesProvider('https://api.example.com', { }); ``` -Custom providers that don't extend a REST provider should reject, not stay pending, when a request can't complete. See [Request timeouts](/docs/design/request-timeouts). +See [Request timeouts](/docs/design/request-timeouts). ### Caching and Performance diff --git a/apps/documentation/pages/docs/service-registry/providers.mdx b/apps/documentation/pages/docs/service-registry/providers.mdx index 8cc59459..66d934ea 100644 --- a/apps/documentation/pages/docs/service-registry/providers.mdx +++ b/apps/documentation/pages/docs/service-registry/providers.mdx @@ -40,7 +40,7 @@ constructor(baseUrl: string, options?: { timeout?: number }) **Parameters:** - `baseUrl`: The base URL of the Service Registry API endpoint (e.g., `https://registry.example.com/ga4gh/registry/v1`) -- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). +- `options.timeout`: request deadline in milliseconds (default 30 s, `0` for none). See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -264,8 +264,6 @@ class CustomServiceRegistryProvider extends RestServiceRegistryProvider { } ``` -Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `ServiceRegistryProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). - For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/apps/documentation/pages/docs/tes/providers.mdx b/apps/documentation/pages/docs/tes/providers.mdx index cea55f17..986ff4f4 100644 --- a/apps/documentation/pages/docs/tes/providers.mdx +++ b/apps/documentation/pages/docs/tes/providers.mdx @@ -40,7 +40,7 @@ constructor(baseUrl: string, options?: { timeout?: number }) **Parameters:** - `baseUrl`: The base URL of the TES API endpoint (e.g., `https://protes.rahtiapp.fi/ga4gh/tes/v1`) -- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). +- `options.timeout`: request deadline in milliseconds (default 30 s, `0` for none). See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -455,8 +455,6 @@ const provider = new AuthTesProvider( Tokens used in browser code are visible to users. Prefer short-lived tokens, and never embed long-lived secrets in client-side bundles. -Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `TesProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). - For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/apps/documentation/pages/docs/trs-filer/providers.mdx b/apps/documentation/pages/docs/trs-filer/providers.mdx index 1344f6ae..c717adc6 100644 --- a/apps/documentation/pages/docs/trs-filer/providers.mdx +++ b/apps/documentation/pages/docs/trs-filer/providers.mdx @@ -84,7 +84,7 @@ constructor(baseUrl: string, options?: { timeout?: number }) **Parameters:** - `baseUrl`: The base URL of the TRS Filer API endpoint (e.g., `https://trs-filer.example.com/ga4gh/trs/v2`) -- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). +- `options.timeout`: request deadline in milliseconds (default 30 s, `0` for none). See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -498,8 +498,6 @@ class CustomTrsFilerProvider extends RestTrsFilerProvider { } ``` -Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `TrsFilerProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). - For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/apps/documentation/pages/docs/trs/providers.mdx b/apps/documentation/pages/docs/trs/providers.mdx index 2a26ddcb..130138b7 100644 --- a/apps/documentation/pages/docs/trs/providers.mdx +++ b/apps/documentation/pages/docs/trs/providers.mdx @@ -69,7 +69,7 @@ constructor(baseUrl: string, options?: { timeout?: number }) **Parameters:** - `baseUrl`: The base URL of the TRS API endpoint (e.g., `https://dockstore.org/api/ga4gh/trs/v2`) -- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). +- `options.timeout`: request deadline in milliseconds (default 30 s, `0` for none). See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -471,8 +471,6 @@ class CustomTrsProvider extends RestTrsProvider { } ``` -Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `TrsProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). - For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing diff --git a/apps/documentation/pages/docs/wes/providers.mdx b/apps/documentation/pages/docs/wes/providers.mdx index 253ed1a0..ea465329 100644 --- a/apps/documentation/pages/docs/wes/providers.mdx +++ b/apps/documentation/pages/docs/wes/providers.mdx @@ -38,7 +38,7 @@ constructor(baseUrl: string, options?: { timeout?: number }) **Parameters:** - `baseUrl`: The base URL of the WES API endpoint (e.g., `https://weskit.example.com/ga4gh/wes/v1`) -- `options.timeout`: Deadline of each request in milliseconds, until its response has been read (default `30000`, `0` for none). An expired request rejects with a `RequestTimeoutError`, and components show it as an error. See [Request timeouts](/docs/design/request-timeouts). The deadline includes uploading the attachments of `runWorkflow()`: raise it for large attachments. +- `options.timeout`: request deadline in milliseconds (default 30 s, `0` for none). See [Request timeouts](/docs/design/request-timeouts). ### Basic Usage @@ -350,8 +350,6 @@ class CustomWesProvider extends RestWesProvider { } ``` -Calling `super.fetch()` keeps the provider's request deadline (`timeout`). A provider that implements `WesProvider` directly sets its own deadlines: its methods should reject, not stay pending, when a request can't complete, or the components keep loading (see [Request timeouts](/docs/design/request-timeouts)). - For comprehensive patterns and examples, see the [Providers Overview](/docs/providers) documentation. ## Testing