Skip to content

Commit

Permalink
Unblock handshake ch on close
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Aug 12, 2024
1 parent 18c4015 commit 194ba43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 19 additions & 4 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,11 @@ func (a *Association) handleCookieEcho(c *chunkCookieEcho) []*packet {

a.setState(established)
// Note: This is a future place where the user could be notified (COMMUNICATION UP)
a.handshakeCompletedCh <- nil
select {
case a.handshakeCompletedCh <- nil:
case <-a.closeWriteLoopCh: // check the write side since we are in a read path
return nil

Check warning on line 1382 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L1381-L1382

Added lines #L1381 - L1382 were not covered by tests
}
}

p := &packet{
Expand Down Expand Up @@ -1405,7 +1409,10 @@ func (a *Association) handleCookieAck() {

a.setState(established)
// Note: This is a future place where the user could be notified (COMMUNICATION UP)
a.handshakeCompletedCh <- nil
select {
case a.handshakeCompletedCh <- nil:
case <-a.closeWriteLoopCh: // check the write side since we are in a read path

Check warning on line 1414 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L1414

Added line #L1414 was not covered by tests
}
}

// The caller should hold the lock.
Expand Down Expand Up @@ -2698,13 +2705,21 @@ func (a *Association) onRetransmissionFailure(id int) {

if id == timerT1Init {
a.log.Errorf("[%s] retransmission failure: T1-init", a.name)
a.handshakeCompletedCh <- ErrHandshakeInitAck
select {
case a.handshakeCompletedCh <- ErrHandshakeInitAck:
case <-a.closeWriteLoopCh: // check the read/write sides
case <-a.readLoopCloseCh:

Check warning on line 2711 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L2710-L2711

Added lines #L2710 - L2711 were not covered by tests
}
return
}

if id == timerT1Cookie {
a.log.Errorf("[%s] retransmission failure: T1-cookie", a.name)
a.handshakeCompletedCh <- ErrHandshakeCookieEcho
select {
case a.handshakeCompletedCh <- ErrHandshakeCookieEcho:
case <-a.closeWriteLoopCh: // check the read/write sides
case <-a.readLoopCloseCh:

Check warning on line 2721 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L2720-L2721

Added lines #L2720 - L2721 were not covered by tests
}
return
}

Expand Down
4 changes: 4 additions & 0 deletions association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,10 @@ func TestAssociation_Abort(t *testing.T) {

// TestAssociation_createClientWithContext tests that the client is closed when the context is canceled.
func TestAssociation_createClientWithContext(t *testing.T) {
// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 5)
defer lim.Stop()

checkGoroutineLeaks(t)

udp1, udp2 := createUDPConnPair()
Expand Down

0 comments on commit 194ba43

Please sign in to comment.