Harden WebBFF and deployment release behavior
Model fail-closed cross-replica session renewal and implement owner-fenced refresh, transient observer handling, logout fencing, and graceful shutdown. Remove chart-owned Ingress while retaining qualification-owned external routing.
This commit is contained in:
parent
ffa65018ed
commit
414b380516
1 changed files with 980 additions and 136 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { WebSocket, WebSocketServer } from 'ws'
|
||||
|
||||
import { validBrowserContext, validUnsafeRequest } from './oauth.mjs'
|
||||
import { equalSecret, sessionCookie } from './sessions.mjs'
|
||||
import { equalSecret } from './sessions.mjs'
|
||||
|
||||
const MAX_REQUEST_BYTES = 1024 * 1024
|
||||
const MAX_EVENT_BYTES = 1024 * 1024
|
||||
|
|
@ -90,11 +90,6 @@ export class ApiProxy {
|
|||
signal: AbortSignal.timeout(API_TIMEOUT_MILLISECONDS),
|
||||
})
|
||||
const responseHeaders = { 'Cache-Control': 'no-store' }
|
||||
if (loaded.rotated)
|
||||
responseHeaders['Set-Cookie'] = sessionCookie(
|
||||
loaded.identifier,
|
||||
this.config,
|
||||
)
|
||||
for (const name of ['content-type', 'traceparent'])
|
||||
if (upstreamResponse.headers.has(name))
|
||||
responseHeaders[name] = upstreamResponse.headers.get(name)
|
||||
|
|
@ -136,6 +131,17 @@ export class ApiProxy {
|
|||
})
|
||||
return true
|
||||
}
|
||||
|
||||
close() {
|
||||
for (const browser of this.webSockets.clients) {
|
||||
browser.close(1012, 'service restart')
|
||||
const timeout = setTimeout(() => {
|
||||
if (browser.readyState !== WebSocket.CLOSED) browser.terminate()
|
||||
}, 1_000)
|
||||
timeout.unref()
|
||||
}
|
||||
this.webSockets.close()
|
||||
}
|
||||
}
|
||||
|
||||
function copyHeader(request, headers, name) {
|
||||
|
|
@ -169,6 +175,7 @@ function relay(browser, upstream) {
|
|||
}
|
||||
const closeUpstream = (code = 1011, reason = '') => {
|
||||
if (upstream.readyState === WebSocket.OPEN) upstream.close(code, reason)
|
||||
else if (upstream.readyState === WebSocket.CONNECTING) upstream.terminate()
|
||||
}
|
||||
upstream.on('close', closeBrowser)
|
||||
browser.on('close', closeUpstream)
|
||||
|
|
|
|||
Loading…
Reference in a new issue