Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set target socket max listeners to infinity #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export const chain = (
client.on('connect', (response, targetSocket, clientHead) => {
countTargetBytes(sourceSocket, targetSocket);

// There may be many .on('close') listeners, so we need to increase the limit.
targetSocket.setMaxListeners(Infinity);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this risky? The warning is there to help detect memory leaks, now we turn this off and if proxy starts crashing, we won't even know why. Maybe increase it too like 1000 instead?


if (sourceSocket.readyState !== 'open') {
// Sanity check, should never reach.
targetSocket.destroy();
Expand Down
2 changes: 2 additions & 0 deletions src/chain_socks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const chainSocks = async ({
destination,
});
targetSocket = client.socket;
// There may be many .on('close') listeners, so we need to increase the limit.
targetSocket.setMaxListeners(Infinity);

sourceSocket.write(`HTTP/1.1 200 Connection Established\r\n\r\n`);
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions src/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const direct = (
sourceSocket.destroy(error as Error);
}
});
// There may be many .on('close') listeners, so we need to increase the limit.
targetSocket.setMaxListeners(Infinity);

countTargetBytes(sourceSocket, targetSocket);

Expand Down
Loading