Skip to content

Commit 213a54a

Browse files
authored
fix: abort open connection and new stream (#3106)
Check the abort signal and throw if it has been aborted
1 parent 5c1de24 commit 213a54a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/interface-compliance-tests/src/mocks/connection-manager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
55
import { connectionPair } from './connection.js'
66
import type { PrivateKey, PeerId, ComponentLogger, Libp2pEvents, PendingDial, Connection, TypedEventTarget, PubSub, Startable } from '@libp2p/interface'
77
import type { ConnectionManager, Registrar } from '@libp2p/interface-internal'
8+
import type { AbortOptions } from 'it-pushable'
89

910
export interface MockNetworkComponents {
1011
peerId: PeerId
@@ -101,11 +102,13 @@ class MockConnectionManager implements ConnectionManager, Startable {
101102
return 10_000
102103
}
103104

104-
async openConnection (peerId: PeerId | Multiaddr | Multiaddr[]): Promise<Connection> {
105+
async openConnection (peerId: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<Connection> {
105106
if (isMultiaddr(peerId)) {
106107
throw new UnsupportedOperationError('Dialing multiaddrs not supported')
107108
}
108109

110+
options?.signal?.throwIfAborted()
111+
109112
let existingConnections: Connection[] = []
110113

111114
if (Array.isArray(peerId) && peerId.length > 0) {

packages/interface-compliance-tests/src/mocks/connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class MockConnection implements Connection {
8181
throw new ConnectionClosedError('connection must be open to create streams')
8282
}
8383

84+
options?.signal?.throwIfAborted()
85+
8486
const id = `${Math.random()}`
8587
const stream = await this.muxer.newStream(id)
8688
const result = await mss.select(stream, protocols, {

0 commit comments

Comments
 (0)