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:
+38
-10
@@ -17,7 +17,11 @@ func (c *ClientCommon) sendWithContext(ctx context.Context, msg TransferMsg) (Wa
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendWithContextTimeout(ctx context.Context, msg TransferMsg, writeTimeout time.Duration) (WaitMsg, error) {
|
||||
if err := c.ensureClientSendReady(); err != nil {
|
||||
return c.sendWithContextTimeoutAtRoute(ctx, c.clientSessionRouteSnapshot(), msg, writeTimeout)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendWithContextTimeoutAtRoute(ctx context.Context, route clientSessionRoute, msg TransferMsg, writeTimeout time.Duration) (WaitMsg, error) {
|
||||
if err := c.ensureClientSessionRouteSendReady(route); err != nil {
|
||||
return WaitMsg{}, err
|
||||
}
|
||||
if ctx == nil {
|
||||
@@ -36,7 +40,7 @@ func (c *ClientCommon) sendWithContextTimeout(ctx context.Context, msg TransferM
|
||||
if requiresSignalReplyWait(msg) {
|
||||
wait = c.getPendingWaitPool().createAndStore(msg)
|
||||
}
|
||||
err = c.sendSignalEnvelopeMaybeReliable(env, msg)
|
||||
err = c.sendSignalEnvelopeMaybeReliableAtRoute(route, env, msg)
|
||||
if err != nil {
|
||||
if requiresSignalReplyWait(msg) {
|
||||
c.getPendingWaitPool().removeAndClose(msg.ID)
|
||||
@@ -47,7 +51,11 @@ func (c *ClientCommon) sendWithContextTimeout(ctx context.Context, msg TransferM
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendEnvelope(env Envelope) error {
|
||||
if err := c.ensureClientSendReady(); err != nil {
|
||||
return c.sendEnvelopeAtRoute(c.clientSessionRouteSnapshot(), env)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendEnvelopeAtRoute(route clientSessionRoute, env Envelope) error {
|
||||
if err := c.ensureClientSessionRouteSendReady(route); err != nil {
|
||||
return err
|
||||
}
|
||||
payload, err := c.encodeEnvelopePayload(env)
|
||||
@@ -55,19 +63,23 @@ func (c *ClientCommon) sendEnvelope(env Envelope) error {
|
||||
return err
|
||||
}
|
||||
if batchedControlEnvelope(env) {
|
||||
return c.writeControlPayloadToTransportTimeout(env.controlContext(), payload, env.controlPriority, env.controlTimeout)
|
||||
return c.writeControlPayloadToTransportBindingTimeout(env.controlContext(), route.binding, payload, env.controlPriority, env.controlTimeout)
|
||||
}
|
||||
return c.writePayloadToTransportContextTimeout(env.controlContext(), payload, env.controlTimeout)
|
||||
return c.writePayloadToTransportBindingContextTimeout(env.controlContext(), route.binding, payload, env.controlTimeout)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) dispatchEnvelope(env Envelope, now time.Time) {
|
||||
c.dispatchEnvelopeAtRoute(c.clientSessionRouteSnapshot(), env, now)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) dispatchEnvelopeAtRoute(route clientSessionRoute, env Envelope, now time.Time) {
|
||||
switch env.Kind {
|
||||
case EnvelopeSignalAck:
|
||||
if c.handleSignalAckEnvelope(env) {
|
||||
return
|
||||
}
|
||||
case EnvelopeStreamData:
|
||||
c.dispatchStreamEnvelope(env)
|
||||
c.dispatchStreamEnvelopeAtRoute(route, env)
|
||||
return
|
||||
case EnvelopeSignal:
|
||||
transfer, err := unwrapTransferMsgEnvelope(env, c.sequenceDe)
|
||||
@@ -77,11 +89,12 @@ func (c *ClientCommon) dispatchEnvelope(env Envelope, now time.Time) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if c.handleReceivedSignalReliability(transfer) {
|
||||
if c.handleReceivedSignalReliabilityAtRoute(route, transfer) {
|
||||
return
|
||||
}
|
||||
message := Message{
|
||||
ServerConn: c,
|
||||
clientRoute: route,
|
||||
TransferMsg: transfer,
|
||||
NetType: NET_CLIENT,
|
||||
Time: now,
|
||||
@@ -136,20 +149,31 @@ func (c *ClientCommon) sendWait(msg TransferMsg, timeout time.Duration) (Message
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendCtx(msg TransferMsg, ctx context.Context) (Message, error) {
|
||||
return c.sendCtxAtRoute(c.clientSessionRouteSnapshot(), msg, ctx)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendCtxAtRoute(route clientSessionRoute, msg TransferMsg, ctx context.Context) (Message, error) {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
data, err := c.sendWithContext(ctx, msg)
|
||||
data, err := c.sendWithContextTimeoutAtRoute(ctx, route, msg, 0)
|
||||
if err != nil {
|
||||
return Message{}, publicContextSendError(ctx, err)
|
||||
}
|
||||
stopCh := sessionStopChan(c.clientStopContextSnapshot())
|
||||
stopCh := sessionStopChan(route.sessionStopCtx)
|
||||
transportStopCh := sessionStopChan(route.transportStopCtx)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
c.getPendingWaitPool().removeAndClose(data.TransferMsg.ID)
|
||||
return Message{}, normalizeStreamDeadlineError(ctx.Err())
|
||||
case <-stopCh:
|
||||
return Message{}, errServiceShutdown
|
||||
case <-transportStopCh:
|
||||
c.getPendingWaitPool().removeAndClose(data.TransferMsg.ID)
|
||||
if route.sessionStopCtx != nil && route.sessionStopCtx.Err() != nil {
|
||||
return Message{}, errServiceShutdown
|
||||
}
|
||||
return Message{}, transportDetachedSessionEpochError()
|
||||
case msg, ok := <-data.Reply:
|
||||
if !ok {
|
||||
return msg, pendingWaitClosedErrorWith(stopCh, clientTransportDetachedError(c))
|
||||
@@ -159,11 +183,15 @@ func (c *ClientCommon) sendCtx(msg TransferMsg, ctx context.Context) (Message, e
|
||||
}
|
||||
|
||||
func (c *ClientCommon) SendObjCtx(ctx context.Context, key string, val interface{}) (Message, error) {
|
||||
return c.sendObjCtxAtRoute(ctx, c.clientSessionRouteSnapshot(), key, val)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) sendObjCtxAtRoute(ctx context.Context, route clientSessionRoute, key string, val interface{}) (Message, error) {
|
||||
data, err := c.sequenceEn(val)
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
return c.sendCtx(TransferMsg{
|
||||
return c.sendCtxAtRoute(route, TransferMsg{
|
||||
Key: key,
|
||||
Value: data,
|
||||
Type: MSG_SYNC_ASK,
|
||||
|
||||
Reference in New Issue
Block a user