fix bug when goroutine crashed if lux channel closed before
This commit is contained in:
parent
9e661baad2
commit
80a546b124
2 changed files with 12 additions and 4 deletions
|
|
@ -25,6 +25,7 @@ type LuxChannel struct {
|
|||
Address *net.UDPAddr
|
||||
conn *net.UDPConn
|
||||
preconnected bool
|
||||
control chan bool
|
||||
}
|
||||
|
||||
// bind udp socket to receive packets
|
||||
|
|
@ -44,6 +45,7 @@ func NewLuxInboundChannel(udpStr string, chType LuxChannelType) (LuxChannel, err
|
|||
Address: addr,
|
||||
conn: conn,
|
||||
preconnected: false,
|
||||
control: make(chan bool),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ func (r *LuxRouter) CloseChannel(channel *LuxChannel, closeInbound bool) {
|
|||
if closeInbound {
|
||||
for i, ch := range r.inbound {
|
||||
if &ch == channel {
|
||||
ch.control <- true
|
||||
r.inbound = append(r.inbound[:i], r.inbound[:i+1]...)
|
||||
}
|
||||
}
|
||||
|
|
@ -208,12 +209,17 @@ func channelReceiver(r *LuxRouter, channel *LuxChannel) {
|
|||
var dgram LuxDatagram
|
||||
var err error
|
||||
|
||||
for err == nil {
|
||||
select {
|
||||
case <-channel.control:
|
||||
return
|
||||
default:
|
||||
dgram, err = channel.Recv()
|
||||
dgramChan <- dgram
|
||||
if err == nil {
|
||||
dgramChan <- dgram
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
r.CloseChannel(channel, true)
|
||||
}
|
||||
|
||||
func (r *LuxRouter) Start() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue