Skip to content

Commit dc56856

Browse files
authored
fix: query for circuit relays after start (#2309)
This should be done in the `afterStart` method otherwise the DHT query manager may not have been started yet.
1 parent 984f13e commit dc56856

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

packages/transport-circuit-relay-v2/src/transport/discovery.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
5959
}
6060
})
6161

62+
this.started = true
63+
}
64+
65+
afterStart (): void {
6266
void this.discover()
6367
.catch(err => {
64-
this.log.error('error listening on relays', err)
68+
this.log.error('error discovering relays', err)
6569
})
66-
67-
this.started = true
6870
}
6971

7072
stop (): void {

packages/transport-circuit-relay-v2/src/transport/reservation-store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ export class ReservationStore extends TypedEventEmitter<ReservationStoreEvents>
115115
return this.started
116116
}
117117

118-
async start (): Promise<void> {
118+
start (): void {
119119
this.started = true
120120
}
121121

122-
async stop (): Promise<void> {
122+
stop (): void {
123123
this.reserveQueue.clear()
124124
this.reservations.forEach(({ timeout }) => {
125125
clearTimeout(timeout)

packages/transport-circuit-relay-v2/src/transport/transport.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ export class CircuitRelayTransport implements Transport {
103103
}
104104

105105
async start (): Promise<void> {
106-
await this.reservationStore.start()
107-
await this.discovery?.start()
106+
this.reservationStore.start()
108107

109108
await this.registrar.handle(RELAY_V2_STOP_CODEC, (data) => {
110109
void this.onStop(data).catch(err => {
@@ -117,12 +116,18 @@ export class CircuitRelayTransport implements Transport {
117116
runOnTransientConnection: true
118117
})
119118

119+
await this.discovery?.start()
120+
120121
this.started = true
121122
}
122123

124+
afterStart (): void {
125+
this.discovery?.afterStart()
126+
}
127+
123128
async stop (): Promise<void> {
124129
this.discovery?.stop()
125-
await this.reservationStore.stop()
130+
this.reservationStore.stop()
126131
await this.registrar.unhandle(RELAY_V2_STOP_CODEC)
127132

128133
this.started = false

0 commit comments

Comments
 (0)