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:
parent
065a868115
commit
e7ead1860a
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
|
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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue