use opened promise for tcp connection test
parent
b6702e9958
commit
31a4d9345a
|
|
@ -17,18 +17,12 @@ export async function getStatus(
|
||||||
// TCP port endpoint monitor
|
// TCP port endpoint monitor
|
||||||
try {
|
try {
|
||||||
const [hostname, port] = monitor.target.split(':')
|
const [hostname, port] = monitor.target.split(':')
|
||||||
|
|
||||||
// Write "PING\n"
|
|
||||||
const socket = connect({ hostname: hostname, port: Number(port) })
|
const socket = connect({ hostname: hostname, port: Number(port) })
|
||||||
const writer = socket.writable.getWriter()
|
|
||||||
const reader = socket.readable.getReader()
|
|
||||||
await withTimeout(monitor.timeout || 10000, writer.write(new TextEncoder().encode('PING\n')))
|
|
||||||
await withTimeout(monitor.timeout || 10000, reader.read())
|
|
||||||
await socket.close()
|
|
||||||
|
|
||||||
// Not having an `opened` promise now...
|
// Now we have an `opened` promise!
|
||||||
// https://github.com/cloudflare/workerd/issues/1305
|
// @ts-ignore
|
||||||
// await withTimeout(monitor.timeout || 10000, socket.closed)
|
await withTimeout(monitor.timeout || 10000, socket.opened)
|
||||||
|
await socket.close()
|
||||||
|
|
||||||
console.log(`${monitor.name} connected to ${monitor.target}`)
|
console.log(`${monitor.name} connected to ${monitor.target}`)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue