mirror of
https://github.com/stablyai/orca.git
synced 2026-09-27 08:02:35 +00:00
Phase 6 of the relay split: the relay's deploy/operate surface moves under cloud/ with 24 cloud-* workflows gated on ORCA_CLOUD_OPERATIONS_ENABLED, the Cloud SQL rollout lease action, the relay Terraform root (dual-accept identities for both repositories), scripts, docs, CODEOWNERS, and a terraform validate job in Cloud Verify.
23 lines
824 B
TypeScript
23 lines
824 B
TypeScript
import type WebSocket from 'ws'
|
|
|
|
const RELAY_WEBSOCKET_FORCE_CLOSE_MS = 1_000
|
|
const forceCloseTimers = new WeakMap<WebSocket, ReturnType<typeof setTimeout>>()
|
|
|
|
export function closeRelayWebSocket(socket: WebSocket, code: number, reason: string): void {
|
|
if (socket.readyState === socket.CLOSED) return
|
|
if (!forceCloseTimers.has(socket)) {
|
|
const timer = setTimeout(() => {
|
|
forceCloseTimers.delete(socket)
|
|
if (socket.readyState !== socket.CLOSED) socket.terminate()
|
|
}, RELAY_WEBSOCKET_FORCE_CLOSE_MS)
|
|
timer.unref()
|
|
forceCloseTimers.set(socket, timer)
|
|
socket.once('close', () => {
|
|
const pending = forceCloseTimers.get(socket)
|
|
if (pending) clearTimeout(pending)
|
|
forceCloseTimers.delete(socket)
|
|
})
|
|
}
|
|
if (socket.readyState === socket.OPEN) socket.close(code, reason)
|
|
}
|