diff --git a/package.json b/package.json index 8118f23..ce52bf2 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "ms": "^2.1.3", "secure-json-parse": "^2.4.0", "tslib": "^2.3.0", - "undici": "^4.7.0" + "undici": "^4.14.1" }, "tap": { "ts": true, diff --git a/src/connection/UndiciConnection.ts b/src/connection/UndiciConnection.ts index 5ba6cf4..cacbe6c 100644 --- a/src/connection/UndiciConnection.ts +++ b/src/connection/UndiciConnection.ts @@ -69,7 +69,7 @@ export default class Connection extends BaseConnection { this[kEmitter] = new EventEmitter() const undiciOptions: Pool.Options = { - keepAliveTimeout: 4000, + keepAliveTimeout: 600e3, keepAliveMaxTimeout: 600e3, keepAliveTimeoutThreshold: 1000, pipelining: 1, @@ -200,25 +200,16 @@ export default class Connection extends BaseConnection { this.diagnostic.emit('deserialization', null, options) try { if (isCompressed || isVectorTile) { // eslint-disable-line - const payload: Buffer[] = [] - for await (const chunk of response.body) { - payload.push(chunk) - } return { statusCode: response.statusCode, headers: response.headers, - body: Buffer.concat(payload) + body: Buffer.from(await response.body.arrayBuffer()) } } else { - let payload = '' - response.body.setEncoding('utf8') - for await (const chunk of response.body) { - payload += chunk as string - } return { statusCode: response.statusCode, headers: response.headers, - body: payload + body: await response.body.text() } } } catch (err: any) { diff --git a/test/acceptance/events-order.test.ts b/test/acceptance/events-order.test.ts index b49f206..8e8fd47 100644 --- a/test/acceptance/events-order.test.ts +++ b/test/acceptance/events-order.test.ts @@ -89,6 +89,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty await client.request({ method: 'GET', path: '/' }) t.equal(order.length, 0) server.stop() + await client.close() }) t.test('Connection error', async t => { @@ -132,6 +133,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.ok(err instanceof ConnectionError) t.equal(order.length, 0) } + await client.close() }) t.test('TimeoutError error', async t => { @@ -187,6 +189,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.close() + await client.close() }) t.test('RequestAbortedError error', async t => { @@ -243,6 +246,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.stop() + await client.close() }) t.test('ResponseError error (no retry)', async t => { @@ -297,6 +301,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.stop() + await client.close() }) t.test('ResponseError error (with retry)', async t => { @@ -353,6 +358,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.stop() + await client.close() }) t.test('Serialization Error', async t => { @@ -404,6 +410,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.stop() + await client.close() }) t.test('Deserialization Error', async t => { @@ -456,6 +463,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.stop() + await client.close() }) t.test('Socket destroyed while reading the body', async t => { @@ -514,6 +522,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty t.equal(order.length, 0) } server.stop() + await client.close() }) t.end()