You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create a temporary source and close it after use. The handle needs to be used for a longer period of time, but after I finally close the handle, it results in the source channel being closed multiple times.
func TestSourceClose(t *testing.T) {
h, err := pcap.OpenLive("\\Device\\NPF_Loopback", 65536, false, time.Second*3)
assert.Equal(t, nil, err)
source := gopacket.NewPacketSource(h, nil)
go func() {
for _ = range source.Packets() {
continue
}
println("done")
}()
close(source.Packets())
source2 := gopacket.NewPacketSource(h, nil)
go func() {
for _ = range source2.Packets() {
continue
}
println("done2")
}()
time.Sleep(1 * time.Second)
h.Close()
}
panic: send on closed channel
goroutine 18 [running]:
github.com/google/gopacket.(*PacketSource).packetsToChannel(0xc0000215c0)
D:/code/github.com/gopacket/packet.go:820 +0xb3
created by github.com/google/gopacket.(*PacketSource).Packets in goroutine 7
D:/code/github.com/gopacket/packet.go:861 +0x98
panic: send on closed channel
panic: close of closed channel
goroutine 8 [running]:
github.com/google/gopacket.(*PacketSource).packetsToChannel(0xc0000215c0)
D:/code/github.com/gopacket/packet.go:820 +0xb3
created by github.com/google/gopacket.(*PacketSource).Packets in goroutine 6
D:/code/github.com/gopacket/packet.go:861 +0x98
The text was updated successfully, but these errors were encountered:
I want to create a temporary source and close it after use. The handle needs to be used for a longer period of time, but after I finally close the handle, it results in the source channel being closed multiple times.
The text was updated successfully, but these errors were encountered: