diff --git a/packages/transport-circuit-relay-v2/src/transport/index.ts b/packages/transport-circuit-relay-v2/src/transport/index.ts index 3008ec71ec..e9ed99a726 100644 --- a/packages/transport-circuit-relay-v2/src/transport/index.ts +++ b/packages/transport-circuit-relay-v2/src/transport/index.ts @@ -148,7 +148,7 @@ export class CircuitRelayTransport implements Transport const destinationId = destinationAddr.getComponents().find(c => c.code === CODE_P2P)?.value if (relayId == null || destinationId == null) { - const errMsg = `ircuit relay dial to ${ma.toString()} failed as address did not have both relay and destination PeerIDs` + const errMsg = `circuit relay dial to ${ma.toString()} failed as address did not have both relay and destination PeerIDs` this.log.error(`c${errMsg}`) throw new DialError(`C${errMsg}`) } @@ -165,7 +165,16 @@ export class CircuitRelayTransport implements Transport }) options.onProgress?.(new CustomProgressEvent('circuit-relay:open-connection')) - relayConnection = await this.components.connectionManager.openConnection(relayPeer, options) + + try { + // Dial the concrete relay address first. Peer-id dialing can fail with + // NoValidAddressesError in nested relay/WebRTC flows if candidate + // address discovery/filtering returns no dialable addresses. + relayConnection = await this.components.connectionManager.openConnection(relayAddr, options) + } catch (err: any) { + this.log.error('opening direct relay connection to %a failed, falling back to peer dial for %p - %e', relayAddr, relayPeer, err) + relayConnection = await this.components.connectionManager.openConnection(relayPeer, options) + } } else { options.onProgress?.(new CustomProgressEvent('circuit-relay:reuse-connection')) }