Merge pull request #2098 from lucas-clemente/fix-crypto-setup-close-deadlock

fix deadlock when the crypto setup is closed while qtls writes messages
This commit is contained in:
Marten Seemann
2019-09-01 11:17:42 +07:00
committed by GitHub

View File

@@ -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