mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-24 05:20:01 +00:00
fix: prevent client double close
This commit is contained in:
parent
a3f53e9761
commit
4f14601896
@ -30,6 +30,7 @@ type ObfsUDPHopClientPacketConn struct {
|
||||
|
||||
recvQueue chan *udpPacket
|
||||
closeChan chan struct{}
|
||||
closed bool
|
||||
|
||||
bufPool sync.Pool
|
||||
}
|
||||
@ -112,6 +113,9 @@ func (c *ObfsUDPHopClientPacketConn) hopRoutine() {
|
||||
func (c *ObfsUDPHopClientPacketConn) hop() {
|
||||
c.connMutex.Lock()
|
||||
defer c.connMutex.Unlock()
|
||||
if c.closed {
|
||||
return
|
||||
}
|
||||
newConn, err := net.ListenUDP("udp", nil)
|
||||
if err != nil {
|
||||
log.Printf("udphop: failed to listen on %s: %v", newConn.LocalAddr(), err)
|
||||
@ -175,11 +179,18 @@ func (c *ObfsUDPHopClientPacketConn) WriteTo(b []byte, addr net.Addr) (int, erro
|
||||
func (c *ObfsUDPHopClientPacketConn) Close() error {
|
||||
c.connMutex.Lock()
|
||||
defer c.connMutex.Unlock()
|
||||
if c.closed {
|
||||
return nil
|
||||
}
|
||||
// Close prevConn and currentConn
|
||||
// Close closeChan to unblock ReadFrom & hopRoutine
|
||||
// Set closed flag to true to prevent double close
|
||||
if c.prevConn != nil {
|
||||
_ = c.prevConn.Close()
|
||||
}
|
||||
err := c.currentConn.Close()
|
||||
close(c.closeChan)
|
||||
c.closed = true
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user