1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

fix no corresponding request if req.ID is modified by onSend

This commit is contained in:
Semesse 2023-01-13 22:28:02 +08:00
parent 065a868115
commit e7ead1860a
No known key found for this signature in database
GPG key ID: 126473EEA06D07A8

View file

@ -432,8 +432,7 @@ func (c *Conn) send(_ context.Context, m *anyMessage, wait bool) (cc *call, err
return nil, ErrClosed return nil, ErrClosed
} }
// Store requests so we can later associate them with incoming // Assign a default id if not set
// responses.
if m.request != nil && wait { if m.request != nil && wait {
cc = &call{request: m.request, seq: c.seq, done: make(chan error, 1)} cc = &call{request: m.request, seq: c.seq, done: make(chan error, 1)}
@ -445,8 +444,6 @@ func (c *Conn) send(_ context.Context, m *anyMessage, wait bool) (cc *call, err
m.request.ID.Num = c.seq m.request.ID.Num = c.seq
} }
} }
id = m.request.ID
c.pending[id] = cc
c.seq++ c.seq++
} }
c.mu.Unlock() c.mu.Unlock()
@ -467,6 +464,15 @@ func (c *Conn) send(_ context.Context, m *anyMessage, wait bool) (cc *call, err
} }
} }
// Store requests so we can later associate them with incoming
// responses.
if m.request != nil && wait {
c.mu.Lock()
id = m.request.ID
c.pending[id] = cc
c.mu.Unlock()
}
// From here on, if we fail to send this, then we need to remove // From here on, if we fail to send this, then we need to remove
// this from the pending map so we don't block on it or pile up // this from the pending map so we don't block on it or pile up
// pending entries for unsent messages. // pending entries for unsent messages.