diff --git a/components/DetailBar.tsx b/components/DetailBar.tsx
index a0c37c7..10bfc1f 100644
--- a/components/DetailBar.tsx
+++ b/components/DetailBar.tsx
@@ -1,6 +1,5 @@
import { MonitorState, MonitorTarget } from "@/uptime.types";
import { Box, Tooltip } from "@mantine/core";
-import { useEffect, useRef } from "react";
export default function DetailBar({ monitor, state }: { monitor: MonitorTarget, state: MonitorState }) {
diff --git a/components/MonitorDetail.tsx b/components/MonitorDetail.tsx
index 70bbf62..dc14773 100644
--- a/components/MonitorDetail.tsx
+++ b/components/MonitorDetail.tsx
@@ -22,8 +22,8 @@ export default function MonitorDetail({ monitor, state }: { monitor: MonitorTarg
if (!state.latency[monitor.id]) return (
<>
- {monitor.name}
- No data available, please make sure you have deployed your workers with latest config and check your worker status!
+ {monitor.name}
+ No data available, please make sure you have deployed your workers with latest config and check your worker status!
>
)
diff --git a/worker/src/index.ts b/worker/src/index.ts
index 2d69fd2..b4ca536 100644
--- a/worker/src/index.ts
+++ b/worker/src/index.ts
@@ -1,6 +1,6 @@
import { connect } from 'cloudflare:sockets'
import config from '../../uptime.config'
-import { fetchTimeout, getWorkerLocation } from './util'
+import { fetchTimeout, getWorkerLocation, withTimeout } from './util'
import { MonitorState, MonitorTarget } from "../../uptime.types"
export interface Env {
@@ -30,7 +30,7 @@ async function getStatus(monitor: MonitorTarget): Promise<{ ping: number; up: bo
// Can't do this: await socket.close()
// https://github.com/cloudflare/workerd/issues/1305
- await socket.closed
+ await withTimeout(monitor.timeout || 10000, socket.closed)
console.log(`${monitor.name} connected to ${monitor.target}`)
diff --git a/worker/src/util.ts b/worker/src/util.ts
index f2260e2..692d8ea 100644
--- a/worker/src/util.ts
+++ b/worker/src/util.ts
@@ -14,4 +14,14 @@ const fetchTimeout = (url: string, ms: number, { signal, ...options }: RequestIn
return promise.finally(() => clearTimeout(timeout))
}
-export { getWorkerLocation, fetchTimeout }
+function withTimeout (millis: number, promise: Promise): Promise {
+ const timeout = new Promise((resolve, reject) =>
+ setTimeout(() => reject(new Error(`Promise timed out after ${millis}ms`)), millis))
+
+ return Promise.race([
+ promise,
+ timeout
+ ])
+}
+
+export { getWorkerLocation, fetchTimeout, withTimeout }