sigcn / pg

Another p2p network library in Go 🌍
GNU General Public License v3.0
217 stars 14 forks source link

VPN关闭这部分代码好像存在一个Bug #10

Closed DarkiT closed 4 months ago

DarkiT commented 4 months ago

VPN关闭这部分代码,是不是先关闭连接,再关闭网卡,最后关闭通道会好点,因为先关闭通道了,如果这个时候有数据过来的话,会导致因为通道不存在而panic,所以按下面的方式调整下顺序是不是更合理点?

func (vpn *VPN) Run(ctx context.Context, iface iface.Interface, packetConn net.PacketConn) error {
    vpn.rt = iface
    var wg sync.WaitGroup
    wg.Add(4)
    go vpn.runTunReadEventLoop(&wg, iface.Device())
    go vpn.runTunWriteEventLoop(&wg, iface.Device())
    go vpn.runPacketConnReadEventLoop(&wg, packetConn)
    go vpn.runPacketConnWriteEventLoop(&wg, packetConn)

    <-ctx.Done()
    packetConn.Close()
    iface.Close()
    close(vpn.inbound)
    close(vpn.outbound)
    wg.Wait()
    return nil
}
rkonfj commented 4 months ago

接受 PR

rkonfj commented 4 months ago

f6fa476 这个提交优化了该问题

感谢反馈