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:
+42
-5
@@ -9,9 +9,14 @@ import (
|
||||
)
|
||||
|
||||
type TransportConn struct {
|
||||
logical *LogicalConn
|
||||
generation uint64
|
||||
remoteAddr net.Addr
|
||||
logical *LogicalConn
|
||||
generation uint64
|
||||
remoteAddr net.Addr
|
||||
// binding pins this view to the physical connection that produced it. A
|
||||
// logical session may replace its transport while an operation is in
|
||||
// flight; using the logical's current binding at that point would cross the
|
||||
// reconnect boundary.
|
||||
binding *transportBinding
|
||||
attached bool
|
||||
hasRuntimeConn bool
|
||||
}
|
||||
@@ -19,6 +24,7 @@ type TransportConn struct {
|
||||
const (
|
||||
transportStreamReadBufferSize = 1024 * 1024
|
||||
transportPacketReadBufferSize = 64 * 1024
|
||||
transportFrameMaxPayloadBytes = 64 * 1024 * 1024
|
||||
)
|
||||
|
||||
func streamReadBuffer() []byte {
|
||||
@@ -120,6 +126,7 @@ func (c *LogicalConn) currentTransportConnSnapshot() *TransportConn {
|
||||
logical: logical,
|
||||
generation: c.transportGenerationSnapshot(),
|
||||
remoteAddr: remoteAddr,
|
||||
binding: c.transportBindingSnapshot(),
|
||||
attached: true,
|
||||
hasRuntimeConn: hasRuntimeConn,
|
||||
}
|
||||
@@ -132,6 +139,7 @@ func (c *LogicalConn) currentTransportConnSnapshot() *TransportConn {
|
||||
logical: logical,
|
||||
generation: c.transportGenerationSnapshot(),
|
||||
remoteAddr: remoteAddr,
|
||||
binding: c.transportBindingSnapshot(),
|
||||
attached: true,
|
||||
hasRuntimeConn: hasRuntimeConn,
|
||||
}
|
||||
@@ -197,13 +205,42 @@ func (t *TransportConn) IsCurrent() bool {
|
||||
current := logical.CurrentTransportConn()
|
||||
if current == nil {
|
||||
return false
|
||||
}
|
||||
if current.generation != t.generation {
|
||||
} else if current.generation != t.generation {
|
||||
return false
|
||||
} else if t.binding != nil {
|
||||
return current.binding == t.binding
|
||||
}
|
||||
return transportConnAddrString(current.remoteAddr) == transportConnAddrString(t.remoteAddr)
|
||||
}
|
||||
|
||||
// serverTransportBindingSnapshot returns the physical binding pinned by an
|
||||
// explicit transport. The logical fallback preserves compatibility for
|
||||
// package-local callers that construct TransportConn values directly.
|
||||
func serverTransportBindingSnapshot(logical *LogicalConn, transport *TransportConn) *transportBinding {
|
||||
if transport != nil && transport.binding != nil {
|
||||
return transport.binding
|
||||
}
|
||||
if logical == nil {
|
||||
return nil
|
||||
}
|
||||
return logical.transportBindingSnapshot()
|
||||
}
|
||||
|
||||
// serverTransportBindingSnapshotForConn preserves an inbound socket handoff:
|
||||
// peer attach can transfer the same physical conn from a temporary logical
|
||||
// peer to its stable logical peer. In that case the destination's binding owns
|
||||
// the exact inbound conn and must serialize the reply. A different replacement
|
||||
// conn can never satisfy this identity check, so explicit transport sends stay
|
||||
// pinned to their original binding.
|
||||
func serverTransportBindingSnapshotForConn(logical *LogicalConn, transport *TransportConn, conn net.Conn) *transportBinding {
|
||||
if conn != nil && logical != nil {
|
||||
if current := logical.transportBindingSnapshot(); current != nil && current.connSnapshot() == conn {
|
||||
return current
|
||||
}
|
||||
}
|
||||
return serverTransportBindingSnapshot(logical, transport)
|
||||
}
|
||||
|
||||
func transportConnAddrString(addr net.Addr) string {
|
||||
if addr == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user