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:
@@ -0,0 +1,108 @@
|
||||
package notify
|
||||
|
||||
import "context"
|
||||
|
||||
// clientSessionRoute pins a send or inbound dispatch to one physical client
|
||||
// transport. The logical client session can survive a transport reattach, so
|
||||
// the epoch alone is not sufficient to prevent an old operation from crossing
|
||||
// onto the replacement connection.
|
||||
type clientSessionRoute struct {
|
||||
runtime *clientSessionRuntime
|
||||
binding *transportBinding
|
||||
epoch uint64
|
||||
sessionStopCtx context.Context
|
||||
transportStopCtx context.Context
|
||||
}
|
||||
|
||||
func clientSessionRouteFromRuntime(rt *clientSessionRuntime) clientSessionRoute {
|
||||
if rt == nil {
|
||||
return clientSessionRoute{}
|
||||
}
|
||||
transportStopCtx := rt.transportStopCtx
|
||||
if transportStopCtx == nil {
|
||||
transportStopCtx = rt.stopCtx
|
||||
}
|
||||
return clientSessionRoute{
|
||||
runtime: rt,
|
||||
binding: rt.transport,
|
||||
epoch: rt.epoch,
|
||||
sessionStopCtx: rt.stopCtx,
|
||||
transportStopCtx: transportStopCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func clientSessionRouteContext(route clientSessionRoute) context.Context {
|
||||
if route.transportStopCtx != nil {
|
||||
return route.transportStopCtx
|
||||
}
|
||||
return route.sessionStopCtx
|
||||
}
|
||||
|
||||
func sameClientSessionRoute(left, right clientSessionRoute) bool {
|
||||
if left.runtime != nil || right.runtime != nil {
|
||||
return left.runtime != nil && left.runtime == right.runtime
|
||||
}
|
||||
if left.binding != nil || right.binding != nil {
|
||||
return left.binding != nil && left.binding == right.binding &&
|
||||
(left.epoch == 0 || right.epoch == 0 || left.epoch == right.epoch)
|
||||
}
|
||||
return left.epoch != 0 && left.epoch == right.epoch
|
||||
}
|
||||
|
||||
func (r clientSessionRoute) bound() bool {
|
||||
return r.binding != nil || r.epoch != 0
|
||||
}
|
||||
|
||||
func (r clientSessionRoute) inboundQueueKey() interface{} {
|
||||
if r.binding != nil {
|
||||
return r.binding
|
||||
}
|
||||
return "b612"
|
||||
}
|
||||
|
||||
func (c *ClientCommon) clientSessionRouteSnapshot() clientSessionRoute {
|
||||
if c == nil {
|
||||
return clientSessionRoute{}
|
||||
}
|
||||
return clientSessionRouteFromRuntime(c.clientSessionRuntimeSnapshot())
|
||||
}
|
||||
|
||||
func (c *ClientCommon) clientSessionRouteCurrent(route clientSessionRoute) bool {
|
||||
if c == nil {
|
||||
return false
|
||||
}
|
||||
if !route.bound() {
|
||||
return true
|
||||
}
|
||||
current := c.clientSessionRuntimeSnapshot()
|
||||
if current == nil {
|
||||
return false
|
||||
}
|
||||
if route.epoch != 0 && current.epoch != route.epoch {
|
||||
return false
|
||||
}
|
||||
return route.binding != nil && current.transport == route.binding
|
||||
}
|
||||
|
||||
func (c *ClientCommon) ensureClientSessionRouteSendReady(route clientSessionRoute) error {
|
||||
if err := c.ensureClientSendReady(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !c.clientSessionRouteCurrent(route) {
|
||||
return transportDetachedSessionEpochError()
|
||||
}
|
||||
if route.transportStopCtx != nil {
|
||||
select {
|
||||
case <-route.transportStopCtx.Done():
|
||||
if route.sessionStopCtx != nil && route.sessionStopCtx.Err() != nil {
|
||||
return errServiceShutdown
|
||||
}
|
||||
return transportDetachedSessionEpochError()
|
||||
default:
|
||||
}
|
||||
}
|
||||
if route.binding == nil {
|
||||
return clientTransportDetachedError(c)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user