@@ -1375,8 +1375,9 @@ func (a *Association) handleCookieEcho(c *chunkCookieEcho) []*packet {
1375
1375
a .storedCookieEcho = nil
1376
1376
1377
1377
a .setState (established )
1378
- // Note: This is a future place where the user could be notified (COMMUNICATION UP)
1379
- a .handshakeCompletedCh <- nil
1378
+ if ! a .completeHandshake (nil ) {
1379
+ return nil
1380
+ }
1380
1381
}
1381
1382
1382
1383
p := & packet {
@@ -1404,8 +1405,7 @@ func (a *Association) handleCookieAck() {
1404
1405
a .storedCookieEcho = nil
1405
1406
1406
1407
a .setState (established )
1407
- // Note: This is a future place where the user could be notified (COMMUNICATION UP)
1408
- a .handshakeCompletedCh <- nil
1408
+ a .completeHandshake (nil )
1409
1409
}
1410
1410
1411
1411
// The caller should hold the lock.
@@ -2698,13 +2698,13 @@ func (a *Association) onRetransmissionFailure(id int) {
2698
2698
2699
2699
if id == timerT1Init {
2700
2700
a .log .Errorf ("[%s] retransmission failure: T1-init" , a .name )
2701
- a .handshakeCompletedCh <- ErrHandshakeInitAck
2701
+ a .completeHandshake ( ErrHandshakeInitAck )
2702
2702
return
2703
2703
}
2704
2704
2705
2705
if id == timerT1Cookie {
2706
2706
a .log .Errorf ("[%s] retransmission failure: T1-cookie" , a .name )
2707
- a .handshakeCompletedCh <- ErrHandshakeCookieEcho
2707
+ a .completeHandshake ( ErrHandshakeCookieEcho )
2708
2708
return
2709
2709
}
2710
2710
@@ -2752,3 +2752,17 @@ func (a *Association) MaxMessageSize() uint32 {
2752
2752
func (a * Association ) SetMaxMessageSize (maxMsgSize uint32 ) {
2753
2753
atomic .StoreUint32 (& a .maxMessageSize , maxMsgSize )
2754
2754
}
2755
+
2756
+ // completeHandshake sends the given error to handshakeCompletedCh unless the read/write
2757
+ // side of the association closes before that can happen. It returns whether it was able
2758
+ // to send on the channel or not.
2759
+ func (a * Association ) completeHandshake (handshakeErr error ) bool {
2760
+ select {
2761
+ // Note: This is a future place where the user could be notified (COMMUNICATION UP)
2762
+ case a .handshakeCompletedCh <- handshakeErr :
2763
+ return true
2764
+ case <- a .closeWriteLoopCh : // check the read/write sides for closure
2765
+ case <- a .readLoopCloseCh :
2766
+ }
2767
+ return false
2768
+ }
0 commit comments