fix: 在 OnConnect 把 mochi 发送配额置 0 规避死锁

This commit is contained in:
Nixevol
2026-09-30 16:21:05 +08:00
parent 57c2f70678
commit d94fb25498
4 changed files with 250 additions and 0 deletions
+10
View File
@@ -67,6 +67,16 @@ func (h *nixHook) OnConnect(cl *mqtt.Client, pk packets.Packet) error {
cl.State.ServerKeepalive = true
}
// B-01:绕开 mochi 发送配额路径(NextImmediate 递归读锁 + PUBACK 配额泄漏)。
// ParseConnect 已按客户端 Receive Maximum 设过 sendQuota;此处一律置 0。
if cl.State.Inflight != nil {
cl.State.Inflight.ResetSendQuota(0)
}
if rm := pk.Properties.ReceiveMaximum; rm > 0 && rm < 256 {
h.b.log.Warn("client receive maximum below 256; server ignores MQTT send quota",
"endpoint", endpointID, "receive_maximum", rm)
}
res, err := h.b.auth.Authenticate(context.Background(), endpointID, pk.Connect.Password, remoteIP)
if err != nil {
st.authErr = err