Skip to content

close targetSocket when proxy replies with non-200 status #561

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

Merged
merged 1 commit into from
Nov 16, 2024
Merged

close targetSocket when proxy replies with non-200 status #561

merged 1 commit into from
Nov 16, 2024

Conversation

arenevier
Copy link
Contributor

Fixes issue #560

Copy link
Member

@jancurn jancurn left a comment

Choose a reason for hiding this comment

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

This looks reasonable, thanks for the fix

@jancurn
Copy link
Member

jancurn commented Nov 14, 2024

@jirimoravcik what do you think?

@jirimoravcik
Copy link
Member

Hey @arenevier, can you please provide minimal reproduction code that wouldn't close before this fix and would close with the fix? Thank you

@jirimoravcik jirimoravcik self-requested a review November 14, 2024 13:19
@arenevier
Copy link
Contributor Author

Hey @arenevier, can you please provide minimal reproduction code that wouldn't close before this fix and would close with the fix? Thank you

Here is an example. If I send SIGINT, the server will close. But node process will hang and won't exit properly.

import * as ProxyChain from 'proxy-chain';     ■ Cannot find module 'proxy-chain' or its corresponding type declarations.
  
  async function main() {
  
    const server = new ProxyChain.Server({
      port: 6000,
      host: '127.0.0.1',
H     prepareRequestFunction: (params) => {     ■■ 'params' is declared but its value is never read.
            return {
              upstreamProxyUrl: "http://some.proxy.that.returns.403"
            };
      },
    });
  
    ['SIGINT', 'SIGTERM'].forEach((signal) => {
E     process.once(signal, async () => {     ■ Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev
        console.log('got signal', signal);
        // close the server gracefully
        await server.close(true);
      });
    });
  }
  
  main();

@jirimoravcik jirimoravcik merged commit aa1981b into apify:master Nov 16, 2024
4 checks passed
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