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

Avoid leaking goroutines on close #101

Merged
merged 2 commits into from
Jul 23, 2024
Merged
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
18 changes: 15 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ func (s *Connection) shutdown(closeTimeout time.Duration) {

var timeout <-chan time.Time
if closeTimeout > time.Duration(0) {
timeout = time.After(closeTimeout)
dims marked this conversation as resolved.
Show resolved Hide resolved
timer := time.NewTimer(closeTimeout)
defer timer.Stop()
timeout = timer.C
}
streamsClosed := make(chan bool)

Expand All @@ -739,7 +741,15 @@ func (s *Connection) shutdown(closeTimeout time.Duration) {
}

if err != nil {
dims marked this conversation as resolved.
Show resolved Hide resolved
duration := 10 * time.Minute
// default to 1 second
duration := time.Second
// if a closeTimeout was given, use that, clipped to 1s-10m
if closeTimeout > time.Second {
duration = closeTimeout
}
if duration > 10*time.Minute {
duration = 10 * time.Minute
}
timer := time.NewTimer(duration)
defer timer.Stop()
select {
Expand Down Expand Up @@ -806,7 +816,9 @@ func (s *Connection) CloseWait() error {
func (s *Connection) Wait(waitTimeout time.Duration) error {
var timeout <-chan time.Time
if waitTimeout > time.Duration(0) {
timeout = time.After(waitTimeout)
timer := time.NewTimer(waitTimeout)
defer timer.Stop()
timeout = timer.C
}

select {
Expand Down
Loading