Ping protocol error

Hi everyone,
i notice that using the ping.Ping() Method or pingService.Ping() i receive after few times errors. The first 2 for loop i get the expected RTT result but after the following errors:
pinged … in 0s “stream reset” and after
pinged … in 0s “stream scope not attached to a protocol”

for {
	if len(PeerList) == 0 {
		continue
	}

	fmt.Println("sending 5 ping messages to", PeerList[0].Addrs[0])
	ch := ping.Ping(*ctx, node, PeerList[0].ID)
	for i := 0; i < 5; i++ {
		res := <-ch
		fmt.Println("pinged", PeerList[0].Addrs[0], "in", res.RTT, res.Error)
	}
	time.Sleep(5 * time.Second)
}

I already tried with
node, err := libp2p.New(
libp2p.ListenAddrStrings(“/ip4/127.0.0.1/tcp/0”),
libp2p.Ping(false),
)
if err != nil {
panic(err)
}
// configure our own ping protocol
pingService := &ping.PingService{Host: node}
node.SetStreamHandler(ping.ID, pingService.PingHandler)

Any suggest???

1 Like