From 0ac5d1c149dc49d19b3432456da22e93f94d4a9d Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 14 Feb 2023 10:55:49 +1300 Subject: [PATCH] reduce the size of messageChan channel in the crypto setup (#3664) --- internal/handshake/crypto_setup.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/handshake/crypto_setup.go b/internal/handshake/crypto_setup.go index f9665b61..ec14868c 100644 --- a/internal/handshake/crypto_setup.go +++ b/internal/handshake/crypto_setup.go @@ -263,7 +263,7 @@ func newCryptoSetup( alertChan: make(chan uint8), clientHelloWrittenChan: make(chan struct{}), zeroRTTParametersChan: zeroRTTParametersChan, - messageChan: make(chan []byte, 100), + messageChan: make(chan []byte, 1), isReadingHandshakeMessage: make(chan struct{}), closeChan: make(chan struct{}), version: version, @@ -368,8 +368,15 @@ func (h *cryptoSetup) HandleMessage(data []byte, encLevel protocol.EncryptionLev h.onError(alertUnexpectedMessage, err.Error()) return false } - h.messageChan <- data + if encLevel != protocol.Encryption1RTT { + select { + case h.messageChan <- data: + case <-h.handshakeDone: // handshake errored, nobody is going to consume this message + return false + } + } if encLevel == protocol.Encryption1RTT { + h.messageChan <- data h.handlePostHandshakeMessage() return false }