Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/dispatcher/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@ class Agent extends DispatcherBase {
return dispatcher.dispatch(opts, handler)
}

async [kClose] () {
[kClose] () {
const closePromises = []
for (const { dispatcher } of this[kClients].values()) {
closePromises.push(dispatcher.close())
}
this[kClients].clear()

await Promise.all(closePromises)
return Promise.all(closePromises)
}

async [kDestroy] (err) {
[kDestroy] (err) {
const destroyPromises = []
for (const { dispatcher } of this[kClients].values()) {
destroyPromises.push(dispatcher.destroy(err))
}
this[kClients].clear()

await Promise.all(destroyPromises)
return Promise.all(destroyPromises)
}

get stats () {
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ function onParserTimeout (parser) {
* @param {import('net').Socket} socket
* @returns
*/
async function connectH1 (client, socket) {
function connectH1 (client, socket) {
client[kSocket] = socket

if (!llhttpInstance) {
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function parseH2Headers (headers) {
return result
}

async function connectH2 (client, socket) {
function connectH2 (client, socket) {
client[kSocket] = socket

const session = http2.connect(client[kUrl], {
Expand Down
8 changes: 4 additions & 4 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class Client extends DispatcherBase {
return this[kNeedDrain] < 2
}

async [kClose] () {
[kClose] () {
// TODO: for H2 we need to gracefully flush the remaining enqueued
// request and close each stream.
return new Promise((resolve) => {
Expand All @@ -329,7 +329,7 @@ class Client extends DispatcherBase {
})
}

async [kDestroy] (err) {
[kDestroy] (err) {
return new Promise((resolve) => {
const requests = this[kQueue].splice(this[kPendingIdx])
for (let i = 0; i < requests.length; i++) {
Expand Down Expand Up @@ -444,8 +444,8 @@ async function connect (client) {

try {
client[kHTTPContext] = socket.alpnProtocol === 'h2'
? await connectH2(client, socket)
: await connectH1(client, socket)
? connectH2(client, socket)
: connectH1(client, socket)
} catch (err) {
socket.destroy().on('error', noop)
throw err
Expand Down
28 changes: 12 additions & 16 deletions lib/dispatcher/env-http-proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,20 @@ class EnvHttpProxyAgent extends DispatcherBase {
return agent.dispatch(opts, handler)
}

async [kClose] () {
await this[kNoProxyAgent].close()
if (!this[kHttpProxyAgent][kClosed]) {
await this[kHttpProxyAgent].close()
}
if (!this[kHttpsProxyAgent][kClosed]) {
await this[kHttpsProxyAgent].close()
}
[kClose] () {
return Promise.all([
this[kNoProxyAgent].close(),
!this[kHttpProxyAgent][kClosed] && this[kHttpProxyAgent].close(),
!this[kHttpsProxyAgent][kClosed] && this[kHttpsProxyAgent].close()
])
}

async [kDestroy] (err) {
await this[kNoProxyAgent].destroy(err)
if (!this[kHttpProxyAgent][kDestroyed]) {
await this[kHttpProxyAgent].destroy(err)
}
if (!this[kHttpsProxyAgent][kDestroyed]) {
await this[kHttpsProxyAgent].destroy(err)
}
[kDestroy] (err) {
return Promise.all([
this[kNoProxyAgent].destroy(err),
!this[kHttpProxyAgent][kDestroyed] && this[kHttpProxyAgent].destroy(err),
!this[kHttpsProxyAgent][kDestroyed] && this[kHttpsProxyAgent].destroy(err)
])
}

#getProxyAgentForUrl (url) {
Expand Down
8 changes: 4 additions & 4 deletions lib/dispatcher/h2c-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ class H2CClient extends DispatcherBase {
return this.#client.dispatch(opts, handler)
}

async [kClose] () {
await this.#client.close()
[kClose] () {
return this.#client.close()
}

async [kDestroy] () {
await this.#client.destroy()
[kDestroy] () {
return this.#client.destroy()
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/dispatcher/pool-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ class PoolBase extends DispatcherBase {
return new PoolStats(this)
}

async [kClose] () {
[kClose] () {
if (this[kQueue].isEmpty()) {
await Promise.all(this[kClients].map(c => c.close()))
return Promise.all(this[kClients].map(c => c.close()))
} else {
await new Promise((resolve) => {
return new Promise((resolve) => {
this[kClosedResolve] = resolve
})
}
}

async [kDestroy] (err) {
[kDestroy] (err) {
while (true) {
const item = this[kQueue].shift()
if (!item) {
Expand All @@ -127,7 +127,7 @@ class PoolBase extends DispatcherBase {
item.handler.onError(err)
}

await Promise.all(this[kClients].map(c => c.destroy(err)))
return Promise.all(this[kClients].map(c => c.destroy(err)))
}

[kDispatch] (opts, handler) {
Expand Down
20 changes: 12 additions & 8 deletions lib/dispatcher/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class Http1ProxyWrapper extends DispatcherBase {
return this.#client[kDispatch](opts, handler)
}

async [kClose] () {
[kClose] () {
return this.#client.close()
}

async [kDestroy] (err) {
[kDestroy] (err) {
return this.#client.destroy(err)
}
}
Expand Down Expand Up @@ -220,14 +220,18 @@ class ProxyAgent extends DispatcherBase {
}
}

async [kClose] () {
await this[kAgent].close()
await this[kClient].close()
[kClose] () {
return Promise.all([
this[kAgent].close(),
this[kClient].close()
])
}

async [kDestroy] () {
await this[kAgent].destroy()
await this[kClient].destroy()
[kDestroy] () {
return Promise.all([
this[kAgent].destroy(),
this[kClient].destroy()
])
}
}

Expand Down
Loading