forked from quic-go/quic-go
fix deadlock when the crypto setup is closed while qtls writes messages
This commit is contained in:
@@ -70,7 +70,6 @@ type cryptoSetup struct {
|
|||||||
|
|
||||||
runner handshakeRunner
|
runner handshakeRunner
|
||||||
|
|
||||||
closed bool
|
|
||||||
alertChan chan uint8
|
alertChan chan uint8
|
||||||
// handshakeDone is closed as soon as the go routine running qtls.Handshake() returns
|
// handshakeDone is closed as soon as the go routine running qtls.Handshake() returns
|
||||||
handshakeDone chan struct{}
|
handshakeDone chan struct{}
|
||||||
@@ -283,19 +282,13 @@ func (h *cryptoSetup) RunHandshake() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *cryptoSetup) onError(alert uint8, message string) {
|
func (h *cryptoSetup) onError(alert uint8, message string) {
|
||||||
|
|
||||||
h.runner.OnError(qerr.CryptoError(alert, message))
|
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 {
|
func (h *cryptoSetup) Close() error {
|
||||||
h.mutex.Lock()
|
|
||||||
defer h.mutex.Unlock()
|
|
||||||
|
|
||||||
if h.closed {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
h.closed = true
|
|
||||||
|
|
||||||
close(h.closeChan)
|
close(h.closeChan)
|
||||||
// wait until qtls.Handshake() actually returned
|
// wait until qtls.Handshake() actually returned
|
||||||
<-h.handshakeDone
|
<-h.handshakeDone
|
||||||
|
|||||||
Reference in New Issue
Block a user