Skip to content

Commit

Permalink
Merge pull request #50 from ncdc/fix-write-close-deadlock
Browse files Browse the repository at this point in the history
Fix write/close deadlock
  • Loading branch information
dmcgowan committed Apr 9, 2015
2 parents e731c8f + d91d6d1 commit 99515db
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,25 @@ Loop:
if timer != nil {
timer.Stop()
}

// Start a goroutine to drain resetChan. This is needed because we've seen
// some unit tests with large numbers of goroutines get into a situation
// where resetChan fills up, at least 1 call to Write() is still trying to
// send to resetChan, the connection gets closed, and this case statement
// attempts to grab the write lock that Write() already has, causing a
// deadlock.
//
// See https://github.com/docker/spdystream/issues/49 for more details.
go func() {
for _ = range resetChan {
}
}()

i.writeLock.Lock()
close(resetChan)
i.resetChan = nil
i.writeLock.Unlock()

break Loop
}
}
Expand Down

0 comments on commit 99515db

Please sign in to comment.