-
Notifications
You must be signed in to change notification settings - Fork 145
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
wip: simplify chain #156
wip: simplify chain #156
Conversation
} | ||
|
||
this.log(handlerOpts.id, 'Using HandlerTunnelDirect'); | ||
return direct(request, socket, head); | ||
return direct(request, socket, head, handlerOpts, this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there are just the 3 parameters on direct
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it has 4 params, and you are feeding 5 (and server is 5th, not 4th), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this one :) Now it's 5, handlerOpts
won't be used but I prefer to keep this one so it looks the same like chain
.
https://github.com/apify/proxy-chain/runs/3586133160
@mnmkng I just got the error @rubydev saw before, looks like Node.js selected a protocol that was already in use? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea for future PRs - maybe we should turn the 5 parameters into object
@szmarczak That's weird. Could there be race condition somewhere? |
In the past we used to pick randomized ports, which was a race condition. Now it should be done by operating system, hopefully without races... so this is strange, unless this is an error from an older version? |
Looking at all these PRs, I'm increasingly more worried that this big rewrite can potentially bring a lot of problems to this module that we rely on so heavily. There were a lot of iterations and a lot of real-world testing that went into this module to make sure it was stable and performing well (in particular the socket lifecycle), and now I feel we might be back to square one and might have to go through all the (hard-to-find) errors again, potentially with a big business impact (think of all potential problems a buggy Apify Proxy can cause to our customers). I better stop watching these PRs and I truly hope you guys know what you're doing. Please make sure to write really good comments for the functions, so that other people can understand what's going on. |
}; | ||
|
||
if (proxy.username || proxy.password) { | ||
const auth = `${proxy.username}:${proxy.password}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is either username
or password
is null? Then the auth string will contain "null".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In WHATWG URL it's never null, it's an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With TypeScript we won't have to worry can this be null?
:)
The tests still use Lines 18 to 34 in 0043ac9
so I guess it generated an in-use port. I'm starting to think @rubydev's error is unrelated to this one.
Currently all the tests pass (except the two ones with stats, which will be fixed later). The point of the rewrite is so we don't have to mutate the socket if there's no need to. Only operate on objects we really have to. So if we receive a normal HTTP/1.1 request, let's operate only on
We can gradually roll out the rewrite. Initially e.g. 1% of all requests can go through the rewrite, the next day it can be 5%, the next day it can be 10% etc.
What about it? As I see it, it remains the same. The socket gets closed only when a user does so or there's an error on any side. Am I missing something? If you have any questions, I'm happy to answer them.
I'd prefer if you reviewed the code, you are the creator, but I'm not insisting. This can wait, but needs to be done at some point. I'm trying to keep the code as simple as possible. |
I've added |
Thanks @szmarczak it was just a bit of an old man's afraidness of change that was speaking :) Of course, I'll have a look at the PRs, I'll do a deeper review of the big PR once it's ready. I'm confident your changes will make the module better and cleaner. Just pls comment the functions well, to make it easier to review. Regarding the socket life-cycle, there were some rare strange races that "should never happen" but indeed happened, which led to code blocks like:
These come from battle-testing, so it might happen they will reoccur. But let's see... The gradual roll-out is a good idea, once this is ready pls chat with the Platform team how to do it. |
I understand the worry :)
Thanks a lot ❤️ Two heads always better than one :D
👍🏼
This is also what I'm trying to prevent. proxy-chain/src/handler_base.js Lines 43 to 49 in 0043ac9
therefore there were more critical points that needed to be handled. |
There was a race condition. Before the end socket gets connected the client one to the proxy may get destroyed (e.g. via disconnect). If I understand this right, the I think this PR is good to go. Ready to merge when you are :) |
this PR
wip: simplify forward
wip: simplify custom response
wip: simplify direct
TODO (those will be separate PRs)
direct
andchain
into object