Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Correctly handle link detach and session end.
Browse files Browse the repository at this point in the history
It was possible for `Session.mux` to return before an associated link.
Due to an oversight during refactoring the detach logic did not account
for this and the link could deadlock attempting to send the response
Detach.
  • Loading branch information
vcabbage committed Feb 14, 2018
1 parent 53719b2 commit a3e580d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,10 @@ func (l *link) detach() {
}
select {
case l.session.tx <- fr:
case <-l.session.conn.done:
l.err = l.session.conn.getErr()
case <-l.session.done:
if l.err == nil {
l.err = l.session.err
}
return
}
l.detachSent = true
Expand All @@ -1018,8 +1020,10 @@ func (l *link) detach() {
if l.detachReceived {
select {
case l.session.deallocateHandle <- l:
case <-l.session.conn.done:
l.err = l.session.conn.getErr()
case <-l.session.done:
if l.err == nil {
l.err = l.session.err
}
}
return
}
Expand All @@ -1037,16 +1041,22 @@ outer:
}

// connection has ended
case <-l.session.conn.done:
l.err = l.session.conn.getErr()
case <-l.session.done:
if l.err == nil {
l.err = l.session.err
}
return
}
}

// deallocate handle
select {
case l.session.deallocateHandle <- l:
case <-l.session.conn.done:
l.err = l.session.conn.getErr()
case <-l.session.done:
if l.err == nil {
l.err = l.session.err
}
return
}
}

Expand Down

0 comments on commit a3e580d

Please sign in to comment.