Skip to content

Commit

Permalink
Merge pull request #160 from ngrok/bob/close-once
Browse files Browse the repository at this point in the history
protect against failPermanent writing to closed channel
  • Loading branch information
bobzilladev committed Mar 13, 2024
2 parents 3c55741 + 467099c commit 2fba2d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.9.1

Bug fixes:

- Protect against writing to closed channel on shutdown

## 1.9.0
Enhancements:

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.0
1.9.1
20 changes: 12 additions & 8 deletions internal/tunnel/client/reconnecting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"errors"
"sync"
"sync/atomic"
"time"
"unsafe"
Expand Down Expand Up @@ -94,12 +95,13 @@ func (s *swapRaw) Accept() (netx.LoggedConn, error) {
}

type reconnectingSession struct {
closed int32
dialer RawSessionDialer
stateChanges chan<- error
clientID string
cb ReconnectCallback
sessions []*session
closed int32
dialer RawSessionDialer
stateChanges chan<- error
clientID string
cb ReconnectCallback
sessions []*session
failPermanentOnce sync.Once
log.Logger
}

Expand Down Expand Up @@ -325,8 +327,10 @@ func (s *reconnectingSession) connect(acceptErr error, connSession *session) err
}

failPermanent := func(err error) error {
s.stateChanges <- err
close(s.stateChanges)
s.failPermanentOnce.Do(func() {
s.stateChanges <- err
close(s.stateChanges)
})
return err
}

Expand Down

0 comments on commit 2fba2d6

Please sign in to comment.