fix(notify): 根治低带宽控制面阻塞与传输写入卡死
- 为控制消息增加优先级、公平调度、队列字节预算和自适应批处理 - 支持可取消的写门等待,收紧 shared/dedicated bulk、stream 和 Reply 写入边界 - 修复 bulk reset/close、连接 handoff 和安全 profile 切换时序 - 保留旧取消与超时错误契约,新增阶段化 TransportSendError - 增加 ReplyCtx、ReplyObjCtx、写超时配置及黑洞连接和竞态回归测试
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type TransportSendStage string
|
||||
|
||||
const (
|
||||
TransportSendStageQueue TransportSendStage = "queue"
|
||||
TransportSendStageWrite TransportSendStage = "write"
|
||||
TransportSendStageReply TransportSendStage = "reply"
|
||||
TransportSendStageTransport TransportSendStage = "transport"
|
||||
)
|
||||
|
||||
type TransportSendError struct {
|
||||
Stage TransportSendStage
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *TransportSendError) Error() string {
|
||||
if e == nil {
|
||||
return "transport send error"
|
||||
}
|
||||
if e.Err == nil {
|
||||
return fmt.Sprintf("transport send %s failed", e.Stage)
|
||||
}
|
||||
return fmt.Sprintf("transport send %s failed: %v", e.Stage, e.Err)
|
||||
}
|
||||
|
||||
func (e *TransportSendError) Unwrap() error {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func TransportSendErrorStage(err error) (TransportSendStage, bool) {
|
||||
var sendErr *TransportSendError
|
||||
if !errors.As(err, &sendErr) || sendErr == nil {
|
||||
return "", false
|
||||
}
|
||||
return sendErr.Stage, true
|
||||
}
|
||||
|
||||
func newTransportSendError(stage TransportSendStage, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
var sendErr *TransportSendError
|
||||
if errors.As(err, &sendErr) {
|
||||
return err
|
||||
}
|
||||
return &TransportSendError{Stage: stage, Err: normalizeStreamDeadlineError(err)}
|
||||
}
|
||||
|
||||
// publicContextSendError preserves the legacy public API sentinel when a
|
||||
// context cancellation is the cause of a transport send failure. Internal
|
||||
// callers still receive TransportSendError with its stage information.
|
||||
func publicContextSendError(ctx context.Context, err error) error {
|
||||
if err == nil || ctx == nil {
|
||||
return err
|
||||
}
|
||||
ctxErr := ctx.Err()
|
||||
if ctxErr == nil {
|
||||
return err
|
||||
}
|
||||
normalizedCtxErr := normalizeStreamDeadlineError(ctxErr)
|
||||
if !errors.Is(err, ctxErr) && !errors.Is(err, normalizedCtxErr) {
|
||||
return err
|
||||
}
|
||||
return normalizedCtxErr
|
||||
}
|
||||
Reference in New Issue
Block a user