From e224768e46b4bf39af1d59d274bf8af726c7158d Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 31 Aug 2019 11:47:52 +0700 Subject: [PATCH] fix deadlock when the crypto setup is closed while qtls writes messages --- internal/handshake/crypto_setup.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/internal/handshake/crypto_setup.go b/internal/handshake/crypto_setup.go index 1f47f625..c0882381 100644 --- a/internal/handshake/crypto_setup.go +++ b/internal/handshake/crypto_setup.go @@ -70,7 +70,6 @@ type cryptoSetup struct { runner handshakeRunner - closed bool alertChan chan uint8 // handshakeDone is closed as soon as the go routine running qtls.Handshake() returns handshakeDone chan struct{} @@ -283,19 +282,13 @@ func (h *cryptoSetup) RunHandshake() { } func (h *cryptoSetup) onError(alert uint8, message string) { - h.runner.OnError(qerr.CryptoError(alert, message)) } +// Close closes the crypto setup. +// It aborts the handshake, if it is still running. +// It must only be called once. func (h *cryptoSetup) Close() error { - h.mutex.Lock() - defer h.mutex.Unlock() - - if h.closed { - return nil - } - h.closed = true - close(h.closeChan) // wait until qtls.Handshake() actually returned <-h.handshakeDone