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

feat: closeConnection by id #176

Merged
merged 1 commit into from
May 2, 2022
Merged

Conversation

tomkosm
Copy link
Contributor

@tomkosm tomkosm commented Nov 2, 2021

No description provided.

/**
* Forcibly close a specific pending proxy connection.
*/
closeConnection(connectionId: unknown): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you need this?

Choose a reason for hiding this comment

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

because there are no timeouts and if the remote server keeps connection open/hangs up then it will keep the connection open forever, I had the same issue. I resolved it similarly as in this PR but checking if remote upstream server hasn't sent any bytes yet so its considered as a timeout

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for late reply. I think you could override

onConnection(socket: Socket): void {
(and call super.onConnection(socket)).

Alternatively, you could access proxyChainServer.server to get the underlying native http server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We mainly need that to be able to terminate specific connections, if they overuse their data plans.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Thanks for explanation :)

const socket = this.connections.get(connectionId);
if (!socket) return;

socket.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Destroy actually doesn't destroy the socket (however it tries to close it). See nodejs/node#27428

@szmarczak szmarczak changed the title Add method to close a specific pending proxy connection feat: closeConnection by id May 2, 2022
@szmarczak szmarczak merged commit b5b11af into apify:master May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants