In 0.39.5 we had a simple test that would initialize 10 nodes, have the last 9 nodes dial the first one, publish a message from a random node, and see if it would propagate.
This test started failing when we upgraded to 0.42.2 as first node would start rejecting connections after it had already received 5 connections (i.e. when the 7th node dialed it). Here’s a small jest test to reproduce the error:
import { noise } from '@chainsafe/libp2p-noise';
import { mplex } from '@libp2p/mplex';
import { tcp } from '@libp2p/tcp';
import { createLibp2p, Libp2p } from 'libp2p';
const createNode = async () => {
const node = await createLibp2p({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0'],
},
transports: [tcp()],
streamMuxers: [mplex()],
connectionEncryption: [noise()],
});
return node;
};
const connectAddr = async (source: Libp2p, target: Libp2p) => {
for (const address of target.getMultiaddrs()) {
try {
const conn = await source.dial(address);
if (conn) {
return true;
}
} catch (error: any) {
console.log('error', error);
return false;
}
}
return false;
};
describe('123456', () => {
test('123456', async () => {
const nodes = await Promise.all([
createNode(),
createNode(),
createNode(),
createNode(),
createNode(),
createNode(),
createNode(), // does not fail if you comment this out
]);
for (const node of nodes.slice(1)) {
const res = await connectAddr(node, nodes[0]);
expect(res).toBeTruthy();
}
});
});
The error received is:
error [AggregateError: All promises were rejected] {
[errors]: [
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -54,
code: 'ERR_ENCRYPTION_FAILED',
syscall: 'read'
}
]
}
This can be resolved if we add the peer id to the address book first and then call dial. But I couldn’t find anything obvious in the changelog that points to why dialing the addrs directly should fail after 5.
Any ideas what might be causing this?