Skip to content

Commit 644990a

Browse files
1oca1h0stMecozea
authored andcommitted
fix: improve SSE message logging and queue handling
1 parent 921b418 commit 644990a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/sse/manager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,19 @@ func (m *Manager) listenSSE(ctx context.Context, conn *EndpointConnection) {
411411
connectionTimeout.Stop()
412412
}
413413

414-
log.Debugf("[Master-%d#SSE]MSG: %s", conn.EndpointID, ev.Data)
414+
log.Debugf("[Master-%d#SSE]收到SSE消息: %s", conn.EndpointID, ev.Data)
415415

416416
// 投递到全局 worker pool 异步处理
417417
select {
418418
case m.jobs <- eventJob{endpointID: conn.EndpointID, payload: string(ev.Data)}:
419+
// 成功投递到队列
419420
default:
420421
// 如果队列已满,记录告警,避免阻塞 r3labs 读取协程
421-
log.Warnf("[Master-%d#SSE]事件处理队列已满,丢弃消息", conn.EndpointID)
422+
preview := string(ev.Data)
423+
if len(preview) > 100 {
424+
preview = preview[:100] + "..."
425+
}
426+
log.Warnf("[Master-%d#SSE]事件处理队列已满,丢弃消息: %s", conn.EndpointID, preview)
422427
}
423428
}
424429
}

internal/sse/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ func (s *Service) updateTunnelRuntimeInfo(payload SSEResp) {
439439
return
440440
}
441441

442+
// 检查是否真的更新了记录(可能找不到匹配的tunnel)
443+
if result.RowsAffected == 0 {
444+
log.Warnf("[Master-%d]隧道 %s 运行时信息更新失败:找不到匹配的记录(可能tunnel已被删除)",
445+
payload.EndpointID, payload.Instance.ID)
446+
return
447+
}
448+
442449
log.Debugf("[Master-%d]隧道 %s 运行时信息已更新", payload.EndpointID, payload.Instance.ID)
443450
}
444451

0 commit comments

Comments
 (0)