fix(tunnel): SSE 断开时没通知家里停掉上游请求
server.js 原来用 req.on('aborted') 发 abort,但 SSE 是 GET 无 body,
这个事件只在传输请求体时触发(Node 也已废弃它),实际永远不触发。
后果:前端切会话时 es.close() 关掉旧 SSE,隧道这边收不到 abort,client 继续
读流、继续往 WS 灌数据,core 那边的 SSE 连接也没断。切到正在运行的会话就是
新旧两条流同时推,把单条 WS 占满,后发的 detail 请求只能排队 —— 表现为白屏 1-2 秒。
改挂 res.on('close'):正常结束时 pending 已删会直接返回,只在客户端提前断开时发 abort。
This commit is contained in:
+6
-3
@@ -123,9 +123,12 @@ function handleRequest(req, res, fixedService) {
|
||||
client.send(JSON.stringify({ id, op: 'body', b64: chunk.toString('base64') }));
|
||||
});
|
||||
req.on('end', () => { if (!overflow) client.send(JSON.stringify({ id, op: 'end' })); });
|
||||
// 手机/浏览器提前断开:让家里把上游请求也停掉,别白跑
|
||||
req.on('aborted', () => {
|
||||
if (!pending.has(id)) return;
|
||||
// 客户端提前断开:让家里把上游请求也停掉,别白跑。
|
||||
// 必须挂在 res 上:SSE 是 GET 无 body,req 的 'aborted' 只在传 body 时触发(且已废弃)。
|
||||
// 漏掉这条时,前端关掉 SSE 后 client 会继续读流、继续往 WS 灌数据,切会话时
|
||||
// 新旧两条流同时推,把单条 WS 占满,后发的 detail 请求只能排队。
|
||||
res.on('close', () => {
|
||||
if (!pending.has(id)) return; // 正常结束时 pending 已删
|
||||
client.send(JSON.stringify({ id, op: 'abort' }));
|
||||
pending.delete(id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user