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 (#60)
This commit is contained in:
parent
065a868115
commit
e1f9fdf1bb
1 changed files with 10 additions and 4 deletions
14
jsonrpc2.go
14
jsonrpc2.go
|
|
@ -432,8 +432,7 @@ func (c *Conn) send(_ context.Context, m *anyMessage, wait bool) (cc *call, err
|
|||
return nil, ErrClosed
|
||||
}
|
||||
|
||||
// Store requests so we can later associate them with incoming
|
||||
// responses.
|
||||
// Assign a default id if not set
|
||||
if m.request != nil && wait {
|
||||
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
|
||||
}
|
||||
}
|
||||
id = m.request.ID
|
||||
c.pending[id] = cc
|
||||
c.seq++
|
||||
}
|
||||
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
|
||||
// this from the pending map so we don't block on it or pile up
|
||||
// pending entries for unsent messages.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue