I am posting this for future reference and for anyone experiencing the same issue.
I have added some logs to the DHT on a side project that connects to the IPFS DHT and performs some requests. I have noticed that sometimes some Dials fail with the following error: system: cannot reserve connection: resource limit exceeded
At first it seemed an issue related with the limit on the number of file descriptors, but the issue persisted even after increasing the limit.
This program was running on a server in Azure with an ulimit of 64000
.
I also tried to run this on a Macbook Pro with an ulimit of 10240
.
We run the DHT with default parameters, and configure a libp2p host with tcp, wc, and quic transports:
transports := libp2p.ChainOptions(
libp2p.Transport(tcp.NewTCPTransport),
libp2p.Transport(ws.New),
libp2p.Transport(quic.NewTransport),
)
listenAddrs := libp2p.ListenAddrStrings(
"/ip4/0.0.0.0/tcp/0",
"/ip4/0.0.0.0/tcp/0/ws",
"/ip4/0.0.0.0/udp/0/quic",
)
opts := []libp2p.Option{
libp2p.Identity(priv),
transports,
listenAddrs,
libp2p.DefaultConnectionManager,
}
h, err := libp2p.New(opts...)
dht, err := kad.New(ctx, h, kad.Mode(1), kad.BootstrapPeers(kad.GetDefaultBootstrapPeerAddrInfos()...), kad.LogToFile(cfg.Agent.DHTLogs, os.O_APPEND|os.O_WRONLY|os.O_CREATE))
...
After that point we provide keys on the DHT.
After providing keys on the DHT we search for a random key on the DHT every second.
The issue seems to occur when trying to search for the key.
I don’t known exactly how many connections it had (I am also not sure how to get that information), but I can try to get it if it helps.
From what I can gather from my logs, it seems that connections are still possible after the first error, but infrequent as it looks like the following dial attempts fall in the same error.
I have been pointed to try to increase the resources of DHT in the libp2p network resource manager go-libp2p-resource-manager/README.md at master · libp2p/go-libp2p-resource-manager · GitHub.
I’ll try this and get back to.