fix(01-review): sweep #5 surface port-replaced-during-fetch diagnostic on buffer timeout

This commit is contained in:
2026-05-16 11:00:55 +02:00
parent 7c91f526d8
commit 034155bc4e

View File

@@ -133,7 +133,20 @@ async function getVideoBufferFromOffscreen(): Promise<VideoBufferResponse> {
return new Promise<VideoBufferResponse>((resolve) => { return new Promise<VideoBufferResponse>((resolve) => {
const timer = setTimeout(() => { const timer = setTimeout(() => {
port.onMessage.removeListener(handler); port.onMessage.removeListener(handler);
logger.warn(`Buffer fetch timed out after ${BUFFER_FETCH_TIMEOUT_MS} ms`); // Sweep #5 fix: surface the diagnostic when the timeout fires
// because the port was replaced by a reconnect mid-request.
// The OLD port (captured as `port`) has a dead listener; the
// offscreen will encode-and-send on the NEW port but the
// listener installed there belongs to a different
// getVideoBufferFromOffscreen call (if any). Without this
// diagnostic the operator sees a silent timeout that masquerades
// as an offscreen-side problem. With it, the SW log shows the
// reconnect timing was the proximate cause.
const portReplaced = videoPort !== port;
logger.warn(
`Buffer fetch timed out after ${BUFFER_FETCH_TIMEOUT_MS} ms`,
'port_replaced_during_fetch:', portReplaced,
);
resolve({ segments: [] }); resolve({ segments: [] });
}, BUFFER_FETCH_TIMEOUT_MS); }, BUFFER_FETCH_TIMEOUT_MS);
const handler = (msg: unknown) => { const handler = (msg: unknown) => {