fix: register supplier response waiter before reader can consume reply
CSS quality / css-quality (push) Has been cancelled

This commit is contained in:
hectorzhao
2026-09-16 19:08:42 +08:00
parent a350aca883
commit 010ba32168
5 changed files with 128 additions and 4 deletions
+7 -4
View File
@@ -138,8 +138,8 @@ func (c *connection) submitPart(ctx context.Context, cmd queue.SubmitCommand, pa
c.mu.Lock()
client := c.client
closed := c.closed
c.mu.Unlock()
if closed || client == nil {
c.mu.Unlock()
err := fmt.Errorf("supplier connection is not available")
result := submitResult(cmd, 0, "", "timeout", "CONNECTION_LOST", err.Error())
return 0, "", result, err
@@ -153,6 +153,12 @@ func (c *connection) submitPart(ctx context.Context, cmd queue.SubmitCommand, pa
wireSource = "gateway_write_complete"
}
c.sendMu.Unlock()
// The reader must not consume an immediate response before its waiter is
// registered. Keep the same mu -> sendMu lock order as the heartbeat path.
if err == nil {
c.pending[seq] = rspCh
}
c.mu.Unlock()
if err != nil {
c.emitProtocolLog(protocolLogEvent{
Protocol: "cmpp",
@@ -195,9 +201,6 @@ func (c *connection) submitPart(ctx context.Context, cmd queue.SubmitCommand, pa
},
})
c.mu.Lock()
c.pending[seq] = rspCh
c.mu.Unlock()
defer func() {
c.mu.Lock()
delete(c.pending, seq)