diff --git a/internal/handshake/crypto_setup.go b/internal/handshake/crypto_setup.go index e7cdea4fb..5d46810c4 100644 --- a/internal/handshake/crypto_setup.go +++ b/internal/handshake/crypto_setup.go @@ -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: