forked from quic-go/quic-go
Merge pull request #1937 from lucas-clemente/fix-hrr-race
fix race condition in crypto setup when sending a HelloRetryRequest
This commit is contained in:
@@ -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)
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user