Skip to content

Commit

Permalink
fix: increase default value of max event listeners (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
breno-alves authored Feb 28, 2024
1 parent faa5f1f commit af8ff61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/connection/BaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface ConnectionOptions {
agent?: HttpAgentOptions | UndiciAgentOptions | agentFn | boolean
proxy?: string | URL
caFingerprint?: string
maxEventListeners?: number
}

export interface ConnectionRequestParams {
Expand Down Expand Up @@ -92,6 +93,7 @@ export default class BaseConnection {
resurrectTimeout: number
_openRequests: number
weight: number
maxEventListeners: number
[kStatus]: string
[kCaFingerprint]: string | null
[kDiagnostic]: Diagnostic
Expand All @@ -111,10 +113,10 @@ export default class BaseConnection {
this.resurrectTimeout = 0
this.weight = 0
this._openRequests = 0
this.maxEventListeners = opts.maxEventListeners ?? 100
this[kStatus] = opts.status ?? BaseConnection.statuses.ALIVE
this[kDiagnostic] = opts.diagnostic ?? new Diagnostic()
this[kCaFingerprint] = opts.caFingerprint ?? null

if (!['http:', 'https:'].includes(this.url.protocol)) {
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
}
Expand Down
1 change: 1 addition & 0 deletions src/connection/UndiciConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class Connection extends BaseConnection {
}

this[kEmitter] = new EventEmitter()
this[kEmitter].setMaxListeners(this.maxEventListeners)
const undiciOptions: Pool.Options = {
keepAliveTimeout: 600e3,
keepAliveMaxTimeout: 600e3,
Expand Down
20 changes: 20 additions & 0 deletions test/unit/undici-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,26 @@ test('Path without intial slash', async t => {
server.stop()
})

test('Should increase number of max event listeners', async t => {
t.plan(1)

function handler (req: http.IncomingMessage, res: http.ServerResponse) {
res.end('ok')
}

const [{ port }, server] = await buildServer(handler, { secure: true })
const connection = new UndiciConnection({
url: new URL(`https://localhost:${port}`),
maxEventListeners: 100,
})
const res = await connection.request({
path: '/hello',
method: 'GET'
}, options)
t.equal(res.body, 'ok')
server.stop()
})

test('as stream', async t => {
t.plan(2)

Expand Down

0 comments on commit af8ff61

Please sign in to comment.