|
@@ -90,7 +90,10 @@ func (c *Client) rdyLoop() {
|
|
|
defer atomic.StoreInt32(&c.isConnected, 0)
|
|
|
for {
|
|
|
if frame, err := readFrame(c.conn); err == nil {
|
|
|
- if frame.Func == FuncResponse {
|
|
|
+ switch frame.Func {
|
|
|
+ case FuncPing:
|
|
|
+ c.pintAt = time.Now()
|
|
|
+ case FuncResponse:
|
|
|
c.transactionLocker.RLock()
|
|
|
ch, ok := c.transaction[frame.Sequence]
|
|
|
c.transactionLocker.RUnlock()
|
|
@@ -100,9 +103,9 @@ func (c *Client) rdyLoop() {
|
|
|
} else {
|
|
|
ch.Cancel()
|
|
|
}
|
|
|
+ } else {
|
|
|
+ log.Warnf("RPC: connection %s response %d dropped", c.conn.LocalAddr(), frame.Sequence)
|
|
|
}
|
|
|
- } else if frame.Func == FuncPing {
|
|
|
- c.pintAt = time.Now()
|
|
|
}
|
|
|
} else {
|
|
|
log.Infof("RPC: connection %s closed", c.conn.LocalAddr())
|
|
@@ -182,6 +185,8 @@ func (c *Client) Do(ctx context.Context, req *Request) (res *Response, err error
|
|
|
//canceled
|
|
|
err = io.ErrClosedPipe
|
|
|
}
|
|
|
+ case <-c.exitChan:
|
|
|
+ err = io.ErrClosedPipe
|
|
|
case <-ctx.Done():
|
|
|
trans.Cancel()
|
|
|
err = errors.New("Client.Timeout exceeded while awaiting response")
|
|
@@ -191,6 +196,11 @@ func (c *Client) Do(ctx context.Context, req *Request) (res *Response, err error
|
|
|
|
|
|
func (c *Client) Close() (err error) {
|
|
|
if atomic.CompareAndSwapInt32(&c.exitFlag, 0, 1) {
|
|
|
+ c.transactionLocker.Lock()
|
|
|
+ for _, t := range c.transaction {
|
|
|
+ t.Cancel()
|
|
|
+ }
|
|
|
+ c.transactionLocker.Unlock()
|
|
|
if c.conn != nil {
|
|
|
err = c.conn.Close()
|
|
|
}
|