@@ -162,7 +162,7 @@ type quicState struct {
162162 started bool
163163 signalc chan struct {} // handshake data is available to be read
164164 blockedc chan struct {} // handshake is waiting for data, closed when done
165- cancelc <- chan struct {} // handshake has been canceled
165+ ctx context. Context // handshake context
166166 cancel context.CancelFunc
167167
168168 waitingForDrain bool
@@ -261,10 +261,11 @@ func (q *QUICConn) NextEvent() QUICEvent {
261261
262262// Close closes the connection and stops any in-progress handshake.
263263func (q * QUICConn ) Close () error {
264- if q .conn .quic .cancel == nil {
264+ if q .conn .quic .ctx == nil {
265265 return nil // never started
266266 }
267267 q .conn .quic .cancel ()
268+ <- q .conn .quic .signalc
268269 for range q .conn .quic .blockedc {
269270 // Wait for the handshake goroutine to return.
270271 }
@@ -511,20 +512,16 @@ func (c *Conn) quicWaitForSignal() error {
511512 // Send on blockedc to notify the QUICConn that the handshake is blocked.
512513 // Exported methods of QUICConn wait for the handshake to become blocked
513514 // before returning to the user.
514- select {
515- case c .quic .blockedc <- struct {}{}:
516- case <- c .quic .cancelc :
517- return c .sendAlertLocked (alertCloseNotify )
518- }
515+ c .quic .blockedc <- struct {}{}
519516 // The QUICConn reads from signalc to notify us that the handshake may
520517 // be able to proceed. (The QUICConn reads, because we close signalc to
521518 // indicate that the handshake has completed.)
522- select {
523- case c .quic .signalc <- struct {}{}:
524- c .hand .Write (c .quic .readbuf )
525- c .quic .readbuf = nil
526- case <- c .quic .cancelc :
519+ c .quic .signalc <- struct {}{}
520+ if c .quic .ctx .Err () != nil {
521+ // The connection has been canceled.
527522 return c .sendAlertLocked (alertCloseNotify )
528523 }
524+ c .hand .Write (c .quic .readbuf )
525+ c .quic .readbuf = nil
529526 return nil
530527}
0 commit comments