1f2e74acca
- 完善 stream/bulk DataID 分配、预留和双向命名空间,修复并发打开及 dedicated/shared 回退时的 ID 冲突 - 将收发、回复、恢复任务和 sidecar 绑定原始会话与物理连接,防止重连后的旧消息误操作新连接 - 加强 close/reset 身份校验及实例移除检查,修复 dedicated attach 失败、通道引用和资源回收竞态 - 收紧批量发送器停止准入,确保在途入队完成后统一清理请求、缓冲区和等待者 - 修复 record 满队列死锁、取消时序号消耗及关闭竞态,确保关闭有界并返回真实错误 - 增加协商式 record 逻辑半关闭,保留反向 ACK;通过 reset 传递 RecordFailure,避免背压掩盖原始失败原因 - 补齐帧长度、批次数量、序号溢出和未确认窗口校验,提前拒绝超限数据并按字节预算拆批 - 为入站分发增加全局及单连接的条数、字节预算和阻塞背压,关闭时唤醒等待者,消除正常断连日志噪音 - 完善 bulk 窗口释放失败处理与传输诊断,补充并发、重连、背压、协议边界及真实 TCP 回归覆盖
168 lines
3.6 KiB
Go
168 lines
3.6 KiB
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"sync/atomic"
|
|
)
|
|
|
|
func sessionIsAlive(alive *atomic.Value) (ok bool) {
|
|
if alive == nil {
|
|
return false
|
|
}
|
|
defer func() {
|
|
if recover() != nil {
|
|
ok = false
|
|
}
|
|
}()
|
|
value := alive.Load()
|
|
flag, _ := value.(bool)
|
|
return flag
|
|
}
|
|
|
|
func sessionMarkStarted(alive *atomic.Value, locker sync.Locker, status *Status) {
|
|
if alive != nil {
|
|
alive.Store(true)
|
|
}
|
|
withSessionStatusLock(locker, func() {
|
|
if status == nil {
|
|
return
|
|
}
|
|
*status = Status{
|
|
Alive: true,
|
|
Reason: "",
|
|
Err: nil,
|
|
}
|
|
})
|
|
}
|
|
|
|
func sessionMarkStopped(alive *atomic.Value, locker sync.Locker, status *Status, reason string, err error, stopFn context.CancelFunc, cleanupFns ...func()) {
|
|
if alive != nil {
|
|
alive.Store(false)
|
|
}
|
|
withSessionStatusLock(locker, func() {
|
|
if status == nil {
|
|
return
|
|
}
|
|
*status = Status{
|
|
Alive: false,
|
|
Reason: reason,
|
|
Err: err,
|
|
}
|
|
})
|
|
for _, cleanupFn := range cleanupFns {
|
|
if cleanupFn != nil {
|
|
cleanupFn()
|
|
}
|
|
}
|
|
if stopFn != nil {
|
|
stopFn()
|
|
}
|
|
}
|
|
|
|
func sessionStopChan(stopCtx context.Context) <-chan struct{} {
|
|
if stopCtx == nil {
|
|
return nil
|
|
}
|
|
return stopCtx.Done()
|
|
}
|
|
|
|
func sessionStatusValue(locker sync.Locker, status *Status) Status {
|
|
var snapshot Status
|
|
withSessionStatusLock(locker, func() {
|
|
if status == nil {
|
|
return
|
|
}
|
|
snapshot = *status
|
|
})
|
|
return snapshot
|
|
}
|
|
|
|
func withSessionStatusLock(locker sync.Locker, fn func()) {
|
|
if locker != nil {
|
|
locker.Lock()
|
|
defer locker.Unlock()
|
|
}
|
|
fn()
|
|
}
|
|
|
|
func (c *ClientCommon) markSessionStarted() {
|
|
c.markClientSessionStarted()
|
|
sessionMarkStarted(&c.alive, &c.mu, &c.status)
|
|
}
|
|
|
|
func (c *ClientCommon) markSessionStopped(reason string, err error) {
|
|
if !c.claimClientSessionStop() {
|
|
return
|
|
}
|
|
sessionMarkStopped(&c.alive, &c.mu, &c.status, reason, err, c.clientStopFuncSnapshot(),
|
|
c.clearClientSessionRuntimeTransport,
|
|
c.clearClientSessionRuntimeQueue,
|
|
c.cleanupClientSessionResources,
|
|
)
|
|
c.markClientSessionStopped()
|
|
}
|
|
|
|
func (s *ServerCommon) markSessionStarted() {
|
|
s.markServerSessionStarted()
|
|
sessionMarkStarted(&s.alive, &s.mu, &s.status)
|
|
}
|
|
|
|
func (s *ServerCommon) markSessionStopped(reason string, err error) {
|
|
if !s.claimServerSessionStop() {
|
|
return
|
|
}
|
|
sessionMarkStopped(&s.alive, &s.mu, &s.status, reason, err, s.serverStopFuncSnapshot(),
|
|
s.clearServerSessionRuntimeTransport,
|
|
s.clearServerSessionRuntimeQueue,
|
|
s.cleanupServerSessionResources,
|
|
)
|
|
s.markServerSessionStopped()
|
|
}
|
|
|
|
func (c *ClientConn) markSessionStarted() {
|
|
c.markClientConnLogicalSessionStarted()
|
|
}
|
|
|
|
func (c *ClientConn) markSessionStopped(reason string, err error) {
|
|
c.markClientConnLogicalSessionStopped(reason, err)
|
|
}
|
|
|
|
func (c *ClientCommon) cleanupClientSessionResources() {
|
|
if c == nil {
|
|
return
|
|
}
|
|
state := c.getLogicalSessionState()
|
|
state.pendingWaits.closeAll()
|
|
state.fileAckWaits.closeAll()
|
|
state.signalAckWaits.closeAll()
|
|
state.receivedSignals.closeAll()
|
|
state.transfers.closeAll(errServiceShutdown)
|
|
if runtime := c.getStreamRuntime(); runtime != nil {
|
|
runtime.closeAll(errServiceShutdown)
|
|
}
|
|
if runtime := c.getBulkRuntime(); runtime != nil {
|
|
runtime.closeAll(errServiceShutdown)
|
|
}
|
|
c.closeClientDedicatedSidecar()
|
|
}
|
|
|
|
func (s *ServerCommon) cleanupServerSessionResources() {
|
|
if s == nil {
|
|
return
|
|
}
|
|
state := s.getLogicalSessionState()
|
|
state.pendingWaits.closeAll()
|
|
state.fileAckWaits.closeAll()
|
|
state.signalAckWaits.closeAll()
|
|
state.receivedSignals.closeAll()
|
|
state.transfers.closeAll(errServiceShutdown)
|
|
if runtime := s.getStreamRuntime(); runtime != nil {
|
|
runtime.closeAll(errServiceShutdown)
|
|
}
|
|
if runtime := s.getBulkRuntime(); runtime != nil {
|
|
runtime.closeAll(errServiceShutdown)
|
|
}
|
|
s.closeAllServerDedicatedSidecars()
|
|
}
|