Skip to content

Commit

Permalink
transport: Fix deadlock in client keepalive.
Browse files Browse the repository at this point in the history
When gRPC keepalives are enabled (which isn't the case by default at
this time) and PermitWithoutStream is false (the default), the client
can deadlock when transitioning between having no active stream and
having one active stream.  Subsequent attempts to create a new stream
or to close the client will hang on the transport's mutex, while the
keepalive goroutine is waiting indefinitely on a channel while holding
the transport's mutex.

This fixes #1459.
  • Loading branch information
tsuna committed Aug 23, 2017
1 parent 2308131 commit 76184f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,9 @@ func (t *http2Client) keepalive() {
// Check if keepalive should go dormant.
t.mu.Lock()
if len(t.activeStreams) < 1 && !t.kp.PermitWithoutStream {
t.mu.Unlock()
// Make awakenKeepalive writable.
<-t.awakenKeepalive
t.mu.Unlock()
select {
case <-t.awakenKeepalive:
// If the control gets here a ping has been sent
Expand Down

0 comments on commit 76184f4

Please sign in to comment.