|
@ -197,7 +197,7 @@ func (cli *socketClient) didRecvResponse(res *types.Response) error { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
reqres.Response = res |
|
|
reqres.Response = res |
|
|
reqres.Done() // release waiters
|
|
|
|
|
|
|
|
|
reqres.SetDone() // release waiters
|
|
|
cli.reqSent.Remove(next) // pop first item from linked list
|
|
|
cli.reqSent.Remove(next) // pop first item from linked list
|
|
|
|
|
|
|
|
|
// Notify client listener if set (global callback).
|
|
|
// Notify client listener if set (global callback).
|
|
@ -236,15 +236,8 @@ func (cli *socketClient) Flush(ctx context.Context) error { |
|
|
return err |
|
|
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 { |
|
|
select { |
|
|
case <-gotResp: |
|
|
|
|
|
|
|
|
case <-reqRes.signal: |
|
|
return cli.Error() |
|
|
return cli.Error() |
|
|
case <-ctx.Done(): |
|
|
case <-ctx.Done(): |
|
|
return ctx.Err() |
|
|
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())
|
|
|
// mark all in-flight messages as resolved (they will get cli.Error())
|
|
|
for req := cli.reqSent.Front(); req != nil; req = req.Next() { |
|
|
for req := cli.reqSent.Front(); req != nil; req = req.Next() { |
|
|
reqres := req.Value.(*ReqRes) |
|
|
reqres := req.Value.(*ReqRes) |
|
|
reqres.Done() |
|
|
|
|
|
|
|
|
reqres.SetDone() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Mark all queued messages as resolved.
|
|
|
// Mark all queued messages as resolved.
|
|
@ -500,7 +493,7 @@ func (cli *socketClient) drainQueue(ctx context.Context) { |
|
|
case <-ctx.Done(): |
|
|
case <-ctx.Done(): |
|
|
return |
|
|
return |
|
|
case reqres := <-cli.reqQueue: |
|
|
case reqres := <-cli.reqQueue: |
|
|
reqres.Done() |
|
|
|
|
|
|
|
|
reqres.SetDone() |
|
|
default: |
|
|
default: |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|