Skip to content

Commit

Permalink
fix: increase listeners to silence node warnings (#112)
Browse files Browse the repository at this point in the history
Prevent spurious warnings in the logs.
  • Loading branch information
achingbrain authored Apr 13, 2024
1 parent 8b0fcfd commit 13f4084
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
async * getProviders (cid: CID, options: AbortOptions = {}): AsyncGenerator<PeerRecord> {
log('getProviders starts: %c', cid)

const signal = anySignal([this.shutDownController.signal, options.signal, AbortSignal.timeout(this.timeout)])
const timeoutSignal = AbortSignal.timeout(this.timeout)
const signal = anySignal([this.shutDownController.signal, timeoutSignal, options.signal])
setMaxListeners(Infinity, timeoutSignal, signal)
const onStart = defer()
const onFinish = defer()

Expand Down Expand Up @@ -135,7 +137,9 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
async * getPeers (peerId: PeerId, options: AbortOptions | undefined = {}): AsyncGenerator<PeerRecord> {
log('getPeers starts: %c', peerId)

const signal = anySignal([this.shutDownController.signal, options.signal, AbortSignal.timeout(this.timeout)])
const timeoutSignal = AbortSignal.timeout(this.timeout)
const signal = anySignal([this.shutDownController.signal, timeoutSignal, options.signal])
setMaxListeners(Infinity, timeoutSignal, signal)
const onStart = defer()
const onFinish = defer()

Expand Down Expand Up @@ -198,7 +202,9 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
async getIPNS (peerId: PeerId, options: GetIPNSOptions = {}): Promise<IPNSRecord> {
log('getIPNS starts: %c', peerId)

const signal = anySignal([this.shutDownController.signal, options.signal, AbortSignal.timeout(this.timeout)])
const timeoutSignal = AbortSignal.timeout(this.timeout)
const signal = anySignal([this.shutDownController.signal, timeoutSignal, options.signal])
setMaxListeners(Infinity, timeoutSignal, signal)
const onStart = defer()
const onFinish = defer()

Expand Down Expand Up @@ -256,7 +262,9 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
async putIPNS (peerId: PeerId, record: IPNSRecord, options: AbortOptions = {}): Promise<void> {
log('putIPNS starts: %c', peerId)

const signal = anySignal([this.shutDownController.signal, options.signal, AbortSignal.timeout(this.timeout)])
const timeoutSignal = AbortSignal.timeout(this.timeout)
const signal = anySignal([this.shutDownController.signal, timeoutSignal, options.signal])
setMaxListeners(Infinity, timeoutSignal, signal)
const onStart = defer()
const onFinish = defer()

Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/routes/routing/v1/ipns/get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setMaxListeners } from '@libp2p/interface'
import { peerIdFromCID } from '@libp2p/peer-id'
import { peerIdToRoutingKey } from 'ipns'
import { CID } from 'multiformats/cid'
Expand Down Expand Up @@ -28,6 +29,7 @@ export default function getIpnsV1 (fastify: FastifyInstance, helia: Helia): void
handler: async (request, reply) => {
let peerId: PeerId
const controller = new AbortController()
setMaxListeners(Infinity, controller.signal)

request.raw.on('close', () => {
controller.abort()
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/routes/routing/v1/ipns/put.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setMaxListeners } from '@libp2p/interface'
import { peerIdFromCID } from '@libp2p/peer-id'
import { peerIdToRoutingKey } from 'ipns'
import { ipnsValidator } from 'ipns/validator'
Expand Down Expand Up @@ -36,6 +37,7 @@ export default function putIpnsV1 (fastify: FastifyInstance, helia: Helia): void
handler: async (request, reply) => {
let peerId: PeerId
const controller = new AbortController()
setMaxListeners(Infinity, controller.signal)

request.raw.on('close', () => {
controller.abort()
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/routes/routing/v1/peers/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PassThrough } from 'node:stream'
import { setMaxListeners } from '@libp2p/interface'
import { peerIdFromCID } from '@libp2p/peer-id'
import { CID } from 'multiformats/cid'
import type { Helia } from '@helia/interface'
Expand Down Expand Up @@ -28,6 +29,7 @@ export default function getPeersV1 (fastify: FastifyInstance, helia: Helia): voi
handler: async (request, reply) => {
let peerId: PeerId
const controller = new AbortController()
setMaxListeners(Infinity, controller.signal)

request.raw.on('close', () => {
controller.abort()
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/routes/routing/v1/providers/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PassThrough } from 'node:stream'
import { setMaxListeners } from '@libp2p/interface'
import { CID } from 'multiformats/cid'
import type { Helia } from '@helia/interface'
import type { AbortOptions } from '@libp2p/interface'
Expand Down Expand Up @@ -41,6 +42,7 @@ export default function getProvidersV1 (fastify: FastifyInstance, helia: Helia):
handler: async (request, reply) => {
let cid: CID
const controller = new AbortController()
setMaxListeners(Infinity, controller.signal)

request.raw.on('close', () => {
controller.abort()
Expand Down

0 comments on commit 13f4084

Please sign in to comment.