mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
abci: minor cleanups in the socket client (#3758)
Follow up from #3512 Specifically: cli.conn.Close() need not be under the mutex (#3512 (comment)) call the reqRes callback after the resCb so they always happen in the same order (#3512) Fixes #3513
This commit is contained in:
parent
d041476819
commit
e645442c9b
@ -55,10 +55,6 @@ func NewSocketClient(addr string, mustConnect bool) *socketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) OnStart() error {
|
func (cli *socketClient) OnStart() error {
|
||||||
if err := cli.BaseService.OnStart(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
RETRY_LOOP:
|
RETRY_LOOP:
|
||||||
@ -82,15 +78,12 @@ RETRY_LOOP:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *socketClient) OnStop() {
|
func (cli *socketClient) OnStop() {
|
||||||
cli.BaseService.OnStop()
|
|
||||||
|
|
||||||
cli.mtx.Lock()
|
|
||||||
defer cli.mtx.Unlock()
|
|
||||||
if cli.conn != nil {
|
if cli.conn != nil {
|
||||||
// does this really need a mutex?
|
|
||||||
cli.conn.Close()
|
cli.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cli.mtx.Lock()
|
||||||
|
defer cli.mtx.Unlock()
|
||||||
cli.flushQueue()
|
cli.flushQueue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,19 +202,18 @@ func (cli *socketClient) didRecvResponse(res *types.Response) error {
|
|||||||
reqres.Done() // Release waiters
|
reqres.Done() // Release waiters
|
||||||
cli.reqSent.Remove(next) // Pop first item from linked list
|
cli.reqSent.Remove(next) // Pop first item from linked list
|
||||||
|
|
||||||
// Notify reqRes listener if set (request specific callback).
|
|
||||||
// NOTE: it is possible this callback isn't set on the reqres object.
|
|
||||||
// at this point, in which case it will be called after, when it is set.
|
|
||||||
// TODO: should we move this after the resCb call so the order is always consistent?
|
|
||||||
if cb := reqres.GetCallback(); cb != nil {
|
|
||||||
cb(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify client listener if set (global callback).
|
// Notify client listener if set (global callback).
|
||||||
if cli.resCb != nil {
|
if cli.resCb != nil {
|
||||||
cli.resCb(reqres.Request, res)
|
cli.resCb(reqres.Request, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify reqRes listener if set (request specific callback).
|
||||||
|
// NOTE: it is possible this callback isn't set on the reqres object.
|
||||||
|
// at this point, in which case it will be called after, when it is set.
|
||||||
|
if cb := reqres.GetCallback(); cb != nil {
|
||||||
|
cb(res)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user