Skip to content
Closed
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,18 @@ Agent.prototype.reuseSocket = function reuseSocket(socket, req) {
};

Agent.prototype.destroy = function destroy() {
const sets = [this.freeSockets, this.sockets];
for (var s = 0; s < sets.length; s++) {
var set = sets[s];
var keys = Object.keys(set);
for (var v = 0; v < keys.length; v++) {
var setName = set[keys[v]];
for (var n = 0; n < setName.length; n++) {
setName[n].destroy();
}
destroySockets(this.freeSockets);
destroySockets(this.sockets);
};

function destroySockets(sockets) {
for (const setKey in sockets) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

briefer:

Suggested change
for (const setKey in sockets) {
for (const socket of Object.values(sockets).flat()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But probably also much less performant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in changes the behavior though. Before, the prototype would not be checked but now it does.

I do not know why flat was suggested. It should already be a flat array?

I think in this specific case it should be fine to use Object.values, since it should not be a hot path to destroy the sockets.

var setName = sockets[setKey];
Comment thread
trivikr marked this conversation as resolved.
Outdated
for (const socket of setName) {
socket.destroy();
}
}
};
}

function handleSocketCreation(agent, request, informRequest) {
return function handleSocketCreation_Inner(err, socket) {
Expand Down