|
|
@ -197,7 +197,7 @@ func (cli *socketClient) didRecvResponse(res *types.Response) error { |
|
|
|
} |
|
|
|
|
|
|
|
reqres.Response = res |
|
|
|
reqres.Done() // release waiters
|
|
|
|
reqres.SetDone() // release waiters
|
|
|
|
cli.reqSent.Remove(next) // pop first item from linked list
|
|
|
|
|
|
|
|
// Notify client listener if set (global callback).
|
|
|
@ -236,15 +236,8 @@ func (cli *socketClient) Flush(ctx context.Context) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
gotResp := make(chan struct{}) |
|
|
|
go func() { |
|
|
|
// NOTE: if we don't flush the queue, its possible to get stuck here
|
|
|
|
reqRes.Wait() |
|
|
|
close(gotResp) |
|
|
|
}() |
|
|
|
|
|
|
|
select { |
|
|
|
case <-gotResp: |
|
|
|
case <-reqRes.signal: |
|
|
|
return cli.Error() |
|
|
|
case <-ctx.Done(): |
|
|
|
return ctx.Err() |
|
|
@ -487,7 +480,7 @@ func (cli *socketClient) drainQueue(ctx context.Context) { |
|
|
|
// mark all in-flight messages as resolved (they will get cli.Error())
|
|
|
|
for req := cli.reqSent.Front(); req != nil; req = req.Next() { |
|
|
|
reqres := req.Value.(*ReqRes) |
|
|
|
reqres.Done() |
|
|
|
reqres.SetDone() |
|
|
|
} |
|
|
|
|
|
|
|
// Mark all queued messages as resolved.
|
|
|
@ -500,7 +493,7 @@ func (cli *socketClient) drainQueue(ctx context.Context) { |
|
|
|
case <-ctx.Done(): |
|
|
|
return |
|
|
|
case reqres := <-cli.reqQueue: |
|
|
|
reqres.Done() |
|
|
|
reqres.SetDone() |
|
|
|
default: |
|
|
|
return |
|
|
|
} |
|
|
|