From 121ecb328af41b0b908f1f7f540fd2fe565f2c93 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 22 Jul 2024 08:36:02 -0700 Subject: [PATCH] Added a timeout for fetch (#965) Added a timeout for fetch --- common/spaces/http_space_primitives.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/spaces/http_space_primitives.ts b/common/spaces/http_space_primitives.ts index a42ec0f7..ef437dcd 100644 --- a/common/spaces/http_space_primitives.ts +++ b/common/spaces/http_space_primitives.ts @@ -2,6 +2,8 @@ import { SpacePrimitives } from "./space_primitives.ts"; import { FileMeta } from "../../plug-api/types.ts"; import { flushCachesAndUnregisterServiceWorker } from "../sw_util.ts"; +const fetchTimeout = 5000; + export class HttpSpacePrimitives implements SpacePrimitives { constructor( readonly url: string, @@ -29,6 +31,7 @@ export class HttpSpacePrimitives implements SpacePrimitives { } try { + options.signal = AbortSignal.timeout(fetchTimeout); const result = await fetch(url, options); if (result.status === 503) { throw new Error("Offline");