should fix #4: add a missing withTimeout

This commit is contained in:
lyc8503 committed 2024-01-06 20:17:13 +08:00
1 parent 9bdeec90f2
commit 1e183247cf
1 file changed
+3 -4
+3 -4
View File
@@ -22,7 +22,7 @@ export async function getStatus(
const socket = connect({ hostname: hostname, port: Number(port) })
const writer = socket.writable.getWriter()
const reader = socket.readable.getReader()
await writer.write(new TextEncoder().encode('PING\n'))
await withTimeout(monitor.timeout || 10000, writer.write(new TextEncoder().encode('PING\n')))
await withTimeout(monitor.timeout || 10000, reader.read())
await socket.close()
@@ -63,9 +63,8 @@ export async function getStatus(
if (monitor.expectedCodes) {
if (!monitor.expectedCodes.includes(response.status)) {
status.up = false
status.err = `Expected codes: ${JSON.stringify(monitor.expectedCodes)}, Got: ${
response.status
}`
status.err = `Expected codes: ${JSON.stringify(monitor.expectedCodes)}, Got: ${response.status
}`
return status
}
} else {