-
Notifications
You must be signed in to change notification settings - Fork 565
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: dns interceptor with Pool #3957
base: main
Are you sure you want to change the base?
Conversation
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.
lgtm
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.
The origin should always be in origDispatchOpts
. This seems to be a hack.
I kinda agree, but didn't find where else to put it? |
I made an alternative solution. It currently breaks a test for |
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.
Just adjust the retry
tests and should be ok to go.
The change is kind of expected as the origin is being explicitly passed and is the first origin the client is facing
This still looks weird... where/how does the origin get lost? |
The interceptor does only have access to the options called by .request(). The request method has access to all variables in undici/lib/dispatcher/dispatcher.js Line 23 in c2933ef
It could probably be solved in the same manner for the interceptor by changing: undici/lib/dispatcher/dispatcher.js Line 34 in c2933ef
Into: dispatch = interceptor.bind(this)(dispatch) or something like this (which is a bit like my original approach): dispatch = interceptor(dispatch, this) The last method has the benefit of allowing the interceptors to return arrow functions as well as ordinary functions. |
THis now conflicts, can you rebase? |
43a4023
to
da237d9
Compare
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.
This is wrong... not sure when I have time to look into it. Christmas...
Let me try to check it during the weekend; if there's a workaround, let's take it, otherwise this should be ok for now and we can revisit later so |
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.
The problem here is the assumption that you don't have to pass origin
in the request options if used with Client
or Pool
, which IMHO is incorrect and it's working as intended.
If anything maybe the dns interceptor should check for origin and throw an invalid arg error. Alternatively, if no origin is passed then the dns interceptor is a noop.
|
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.
lgtm
@ronag That was my assumption. Just to be clear, do you think it should be like this? const client = new Pool('https://google.com', {
connections: 10
})
await client.request({
origin: 'https://google.com', // origin must be included in each request
method: 'GET',
path: '/'
}) If that is the case, then I think there are a lot of inconsistencies and contradictions in both the code and documentation. |
Possibly. Then let's just make the dns interceptor a noop when origin is missing as I suggested with the patch. |
I do agree that the documentation has some statements that are either not fully true or confusing for the reader that can lead to a wrong assumption; but that's at an overall take. The last being said; I'm not 100% in sync with the statement that passing the origin should be mandated on every For the latter use-cases, they should have the origin already stick to their state and do not ask the caller to pass it as its goal is to be tight to a single downstream. I'm ok with the |
This relates to...
Rationale
The DNS interceptor didn't work with Pool/Client since it didn't get the origin unless included with each request.
Changes
Features
Bug Fixes
Breaking Changes and Deprecations
Status