Skip to content

Commit ed86ac1

Browse files
committed
fix(connection-manager): address review feedback on per-address timeout
- Fix JSDoc @see URL to point to public ConnectionManagerInit interface instead of internal ConnectionManagerConfig - Replace timing-based assertion in the sequential-hang test with a signal-based one: listen for abort on each hung dial's options.signal and count aborts. Verifies the per-address AbortSignal was actually fired three times rather than measuring wall-clock elapsed time, which is flaky on loaded CI runners.
1 parent cc1c321 commit ed86ac1

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

packages/libp2p/src/connection-manager/constants.defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
export const DIAL_TIMEOUT = 10_000
55

66
/**
7-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#addressDialTimeout
7+
* @see https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionManagerInit.html#addressDialTimeout
88
*/
99
export const ADDRESS_DIAL_TIMEOUT = 6_000
1010

packages/libp2p/test/connection-manager/dial-queue.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ describe('dial queue', () => {
482482
const connection = stubInterface<Connection>()
483483
const addressDialTimeout = 100
484484
const dialledAddrs: string[] = []
485+
let dialsAborted = 0
485486

486487
components.transportManager.dialTransportForMultiaddr.returns(stubInterface<Transport>())
487488
components.transportManager.dial.callsFake(async (ma, options) => {
@@ -490,6 +491,7 @@ describe('dial queue', () => {
490491

491492
if (!maStr.includes('1234')) {
492493
// first three addresses hang – will be cut by per-address timeout
494+
options?.signal?.addEventListener('abort', () => { dialsAborted++ }, { once: true })
493495
return hangUntilAborted(options)
494496
}
495497

@@ -501,14 +503,12 @@ describe('dial queue', () => {
501503
dialTimeout: 10_000
502504
})
503505

504-
const start = Date.now()
505506
const conn = await dialer.dial([
506507
multiaddr('/ip4/127.0.0.1/tcp/1231'),
507508
multiaddr('/ip4/127.0.0.1/tcp/1232'),
508509
multiaddr('/ip4/127.0.0.1/tcp/1233'),
509510
multiaddr('/ip4/127.0.0.1/tcp/1234')
510511
])
511-
const elapsed = Date.now() - start
512512

513513
expect(conn).to.equal(connection)
514514
// all four addresses were attempted in order
@@ -518,9 +518,8 @@ describe('dial queue', () => {
518518
'/ip4/127.0.0.1/tcp/1233',
519519
'/ip4/127.0.0.1/tcp/1234'
520520
])
521-
// elapsed ~= 3 × addressDialTimeout (three per-address timeouts before success)
522-
expect(elapsed).to.be.greaterThan(addressDialTimeout * 2)
523-
expect(elapsed).to.be.lessThan(addressDialTimeout * 6)
521+
// per-address signal was aborted for each of the three hung dials
522+
expect(dialsAborted).to.equal(3)
524523
})
525524

526525
it('should throw an AggregateError when every address times out per-address before the batch timeout', async () => {

0 commit comments

Comments
 (0)