Skip to content

Commit fd2798a

Browse files
authored
Merge pull request #231 from openziti/fix-missing-closes
MultiListener doesn't always close underlays that aren't accepted #230
2 parents f6173be + 6f04187 commit fd2798a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

multi_listener.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package channel
1818

1919
import (
20+
"errors"
2021
"sync"
2122

2223
"github.com/michaelquigley/pfxlog"
@@ -42,7 +43,10 @@ func (self *MultiListener) AcceptUnderlay(underlay Underlay) {
4243

4344
if !isGrouped {
4445
if err := self.ungroupedChannelFallback(underlay); err != nil {
45-
log.WithError(err).Errorf("failed to create channel")
46+
log.WithError(err).Error("failed to create channel")
47+
if closeErr := underlay.Close(); closeErr != nil {
48+
log.WithError(closeErr).Error("error closing underlay")
49+
}
4650
}
4751
return
4852
}
@@ -63,7 +67,7 @@ func (self *MultiListener) AcceptUnderlay(underlay Underlay) {
6367
if !isFirst {
6468
log.Info("no existing channel found for underlay, but isFirstGroupConnection not set, closing connection")
6569
if err := underlay.Close(); err != nil {
66-
log.Info("error closing underlay")
70+
log.WithError(err).Error("error closing underlay")
6771
}
6872
return
6973
}
@@ -74,14 +78,19 @@ func (self *MultiListener) AcceptUnderlay(underlay Underlay) {
7478
self.CloseChannel(chId)
7579
})
7680

77-
if mc != nil {
78-
if err != nil {
79-
log.WithError(err).Errorf("failed to create multi-underlay channel")
80-
} else {
81-
self.lock.Lock()
82-
self.channels[chId] = mc
83-
self.lock.Unlock()
81+
if mc == nil && err == nil {
82+
err = errors.New("multi-channel factory returned nil")
83+
}
84+
85+
if err != nil {
86+
log.WithError(err).Error("failed to create multi-underlay channel")
87+
if closeErr := underlay.Close(); closeErr != nil {
88+
log.WithError(closeErr).Error("error closing underlay")
8489
}
90+
} else {
91+
self.lock.Lock()
92+
self.channels[chId] = mc
93+
self.lock.Unlock()
8594
}
8695
}
8796
}

0 commit comments

Comments
 (0)