fix(notify): 修复传输生命周期竞态,完善背压与协议边界

- 完善 stream/bulk DataID 分配、预留和双向命名空间,修复并发打开及 dedicated/shared 回退时的 ID 冲突
- 将收发、回复、恢复任务和 sidecar 绑定原始会话与物理连接,防止重连后的旧消息误操作新连接
- 加强 close/reset 身份校验及实例移除检查,修复 dedicated attach 失败、通道引用和资源回收竞态
- 收紧批量发送器停止准入,确保在途入队完成后统一清理请求、缓冲区和等待者
- 修复 record 满队列死锁、取消时序号消耗及关闭竞态,确保关闭有界并返回真实错误
- 增加协商式 record 逻辑半关闭,保留反向 ACK;通过 reset 传递 RecordFailure,避免背压掩盖原始失败原因
- 补齐帧长度、批次数量、序号溢出和未确认窗口校验,提前拒绝超限数据并按字节预算拆批
- 为入站分发增加全局及单连接的条数、字节预算和阻塞背压,关闭时唤醒等待者,消除正常断连日志噪音
- 完善 bulk 窗口释放失败处理与传输诊断,补充并发、重连、背压、协议边界及真实 TCP 回归覆盖
This commit is contained in:
2026-09-23 15:33:17 +08:00
parent 0826e17063
commit 1f2e74acca
79 changed files with 9190 additions and 1013 deletions
+24 -9
View File
@@ -12,32 +12,43 @@ import (
const bulkDispatchRejectTimeout = 300 * time.Millisecond
func (c *ClientCommon) dispatchFastBulkFrame(frame bulkFastFrame) {
c.dispatchFastBulkFrameWithOwner(frame, nil)
c.dispatchFastBulkFrameAtRoute(c.clientSessionRouteSnapshot(), frame)
}
func (c *ClientCommon) dispatchFastBulkFrameWithOwner(frame bulkFastFrame, owner *bulkReadPayloadOwner) {
c.dispatchFastBulkFrameWithOwnerAtRoute(c.clientSessionRouteSnapshot(), frame, owner)
}
func (c *ClientCommon) dispatchFastBulkFrameAtRoute(route clientSessionRoute, frame bulkFastFrame) {
c.dispatchFastBulkFrameWithOwnerAtRoute(route, frame, nil)
}
func (c *ClientCommon) dispatchFastBulkFrameWithOwnerAtRoute(route clientSessionRoute, frame bulkFastFrame, owner *bulkReadPayloadOwner) {
if frame.DataID == 0 {
return
}
if route.bound() && !c.clientSessionRouteCurrent(route) {
return
}
runtime := c.getBulkRuntime()
if runtime == nil {
return
}
bulk, ok := runtime.lookupByDataID(clientFileScope(), frame.DataID)
bulk, ok := runtime.lookupInboundFrame(clientFileScope(), frame.DataID)
if !ok {
if c.showError || c.debugMode {
fmt.Println("client bulk data for unknown data id", frame.DataID)
}
c.bestEffortRejectInboundBulkData("", frame.DataID, errBulkNotFound.Error())
c.bestEffortRejectInboundBulkDataAtRoute(route, "", frame.DataID, errBulkNotFound.Error())
return
}
if !bulk.acceptsClientSessionEpoch(c.currentClientSessionEpoch()) {
if !bulk.acceptsClientSessionRoute(route) {
if c.showError || c.debugMode {
fmt.Println("client bulk data rejected by stale session epoch", frame.DataID)
}
detachErr := transportDetachedSessionEpochError()
bulk.markReset(detachErr)
c.bestEffortRejectInboundBulkData(bulk.ID(), frame.DataID, detachErr.Error())
c.bestEffortRejectInboundBulkDataAtRoute(route, bulk.ID(), frame.DataID, detachErr.Error())
return
}
switch frame.Type {
@@ -53,7 +64,7 @@ func (c *ClientCommon) dispatchFastBulkFrameWithOwner(frame bulkFastFrame, owner
fmt.Println("client bulk push chunk error", err)
}
if !errors.Is(err, io.EOF) {
c.bestEffortRejectInboundBulkData(bulk.ID(), frame.DataID, err.Error())
c.bestEffortRejectInboundBulkDataAtRoute(route, bulk.ID(), frame.DataID, err.Error())
}
}
case bulkFastPayloadTypeClose:
@@ -74,7 +85,7 @@ func (c *ClientCommon) dispatchFastBulkFrameWithOwner(frame bulkFastFrame, owner
if c.showError || c.debugMode {
fmt.Println("client bulk release decode error", err)
}
c.bestEffortRejectInboundBulkData(bulk.ID(), frame.DataID, err.Error())
c.bestEffortRejectInboundBulkDataAtRoute(route, bulk.ID(), frame.DataID, err.Error())
return
}
bulk.releaseOutboundWindow(bytes, chunks)
@@ -97,7 +108,7 @@ func (s *ServerCommon) dispatchFastBulkFrameWithOwner(logical *LogicalConn, tran
if runtime == nil {
return
}
bulk, ok := runtime.lookupByDataID(serverFileScope(logical), frame.DataID)
bulk, ok := runtime.lookupInboundFrame(serverFileScope(logical), frame.DataID)
if !ok {
if s.showError || s.debugMode {
fmt.Println("server bulk data for unknown data id", frame.DataID)
@@ -221,12 +232,16 @@ func (s *ServerCommon) tryDispatchBorrowedBulkTransportPayload(source interface{
}
func (c *ClientCommon) bestEffortRejectInboundBulkData(bulkID string, dataID uint64, message string) {
c.bestEffortRejectInboundBulkDataAtRoute(c.clientSessionRouteSnapshot(), bulkID, dataID, message)
}
func (c *ClientCommon) bestEffortRejectInboundBulkDataAtRoute(route clientSessionRoute, bulkID string, dataID uint64, message string) {
if c == nil || (bulkID == "" && dataID == 0) {
return
}
ctx, cancel := context.WithTimeout(context.Background(), bulkDispatchRejectTimeout)
defer cancel()
_, _ = sendBulkResetClient(ctx, c, BulkResetRequest{
_, _ = sendBulkResetClientAtRoute(ctx, c, route, BulkResetRequest{
BulkID: bulkID,
DataID: dataID,
Error: message,