File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -30,37 +30,41 @@ type MultiListener struct {
3030}
3131
3232func (self * MultiListener ) AcceptUnderlay (underlay Underlay ) {
33- self .lock .Lock ()
34- defer self .lock .Unlock ()
35-
3633 log := pfxlog .Logger ().WithField ("underlayId" , underlay .ConnectionId ()).
3734 WithField ("underlayType" , GetUnderlayType (underlay ))
3835
3936 chId := underlay .ConnectionId ()
4037
41- if mc , ok := self .channels [chId ]; ok {
38+ self .lock .Lock ()
39+ mc , ok := self .channels [chId ]
40+ self .lock .Unlock ()
41+
42+ if ok {
4243 log .Info ("found existing channel for underlay" )
4344 mc .AcceptUnderlay (underlay )
4445 } else {
4546 log .Info ("no existing channel found for underlay" )
46- mc , err := self .channelFactory (underlay , func () {
47+ var err error
48+ mc , err = self .channelFactory (underlay , func () {
4749 self .CloseChannel (chId )
4850 })
4951
5052 if mc != nil {
5153 if err != nil {
5254 pfxlog .Logger ().WithError (err ).Errorf ("failed to create multi-underlay channel" )
5355 } else {
56+ self .lock .Lock ()
5457 self .channels [chId ] = mc
58+ self .lock .Unlock ()
5559 }
5660 }
5761 }
5862}
5963
6064func (self * MultiListener ) CloseChannel (chId string ) {
6165 self .lock .Lock ()
62- defer self .lock .Unlock ()
6366 delete (self .channels , chId )
67+ self .lock .Unlock ()
6468}
6569
6670func NewMultiListener (channelF MultiChannelFactory ) * MultiListener {
You can’t perform that action at this time.
0 commit comments