Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unblock handshake ch on close #349

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,9 @@
a.storedCookieEcho = nil

a.setState(established)
// Note: This is a future place where the user could be notified (COMMUNICATION UP)
a.handshakeCompletedCh <- nil
if !a.completeHandshake(nil) {
return nil

Check warning on line 1379 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L1379

Added line #L1379 was not covered by tests
}
}

p := &packet{
Expand Down Expand Up @@ -1404,8 +1405,7 @@
a.storedCookieEcho = nil

a.setState(established)
// Note: This is a future place where the user could be notified (COMMUNICATION UP)
a.handshakeCompletedCh <- nil
a.completeHandshake(nil)
}

// The caller should hold the lock.
Expand Down Expand Up @@ -2698,13 +2698,13 @@

if id == timerT1Init {
a.log.Errorf("[%s] retransmission failure: T1-init", a.name)
a.handshakeCompletedCh <- ErrHandshakeInitAck
a.completeHandshake(ErrHandshakeInitAck)
return
}

if id == timerT1Cookie {
a.log.Errorf("[%s] retransmission failure: T1-cookie", a.name)
a.handshakeCompletedCh <- ErrHandshakeCookieEcho
a.completeHandshake(ErrHandshakeCookieEcho)
return
}

Expand Down Expand Up @@ -2752,3 +2752,17 @@
func (a *Association) SetMaxMessageSize(maxMsgSize uint32) {
atomic.StoreUint32(&a.maxMessageSize, maxMsgSize)
}

// completeHandshake sends the given error to handshakeCompletedCh unless the read/write
// side of the association closes before that can happen. It returns whether it was able
// to send on the channel or not.
func (a *Association) completeHandshake(handshakeErr error) bool {
select {
// Note: This is a future place where the user could be notified (COMMUNICATION UP)
case a.handshakeCompletedCh <- handshakeErr:
return true
case <-a.closeWriteLoopCh: // check the read/write sides for closure
case <-a.readLoopCloseCh:

Check warning on line 2765 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L2764-L2765

Added lines #L2764 - L2765 were not covered by tests
}
return false

Check warning on line 2767 in association.go

View check run for this annotation

Codecov / codecov/patch

association.go#L2767

Added line #L2767 was not covered by tests
}
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
Loading