Skip to content

Commit

Permalink
Merge pull request quic-go#1937 from lucas-clemente/fix-hrr-race
Browse files Browse the repository at this point in the history
fix race condition in crypto setup when sending a HelloRetryRequest
  • Loading branch information
marten-seemann authored May 31, 2019
2 parents 6899eb3 + 0be4ee1 commit aa9ab41
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/handshake/crypto_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func newCryptoSetup(
messageChan: make(chan []byte, 100),
receivedReadKey: make(chan struct{}),
receivedWriteKey: make(chan struct{}),
writeRecord: make(chan struct{}),
writeRecord: make(chan struct{}, 1),
closeChan: make(chan struct{}),
}
qtlsConf := tlsConfigToQtlsConfig(tlsConf, cs, extHandler)
Expand Down Expand Up @@ -510,13 +510,6 @@ func (h *cryptoSetup) SetWriteKey(suite *qtls.CipherSuite, trafficSecret []byte)

// WriteRecord is called when TLS writes data
func (h *cryptoSetup) WriteRecord(p []byte) (int, error) {
defer func() {
select {
case h.writeRecord <- struct{}{}:
default:
}
}()

h.mutex.Lock()
defer h.mutex.Unlock()

Expand All @@ -527,6 +520,11 @@ func (h *cryptoSetup) WriteRecord(p []byte) (int, error) {
if !h.clientHelloWritten && h.perspective == protocol.PerspectiveClient {
h.clientHelloWritten = true
close(h.clientHelloWrittenChan)
} else {
// We need additional signaling to properly detect HelloRetryRequests.
// For servers: when the ServerHello is written.
// For clients: when a reply is sent in response to a ServerHello.
h.writeRecord <- struct{}{}
}
return n, err
case protocol.EncryptionHandshake:
Expand Down

0 comments on commit aa9ab41

Please sign in to comment.