Uh oh!
There was an error while loading. Please reload this page.
fix: dns interceptor with Pool - #3957
Conversation
ronag
left a comment
There was a problem hiding this comment.
The origin should always be in origDispatchOpts. This seems to be a hack.
luddd3
commented
Dec 17, 2024
I kinda agree, but didn't find where else to put it? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
luddd3
commented
Dec 18, 2024
I made an alternative solution. It currently breaks a test for |
metcoder95
left a comment
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ronag
commented
Dec 19, 2024
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. |
mcollina
commented
Dec 19, 2024
THis now conflicts, can you rebase? |
43a4023 to
da237d9Compare
ronag
left a comment
There was a problem hiding this comment.
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 |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ronag
left a comment
There was a problem hiding this comment.
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.
ronag
commented
Dec 20, 2024
|
luddd3
commented
Dec 21, 2024
@ronag That was my assumption. Just to be clear, do you think it should be like this? constclient=newPool('https://google.com',{connections: 10})awaitclient.request({origin: 'https://google.com',// origin must be included in each requestmethod: '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. |
metcoder95
commented
Dec 22, 2024
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 |
luddd3
commented
Dec 27, 2024
I think that Below is an example of how it works today when different import{createServer}from'node:http'import{Client}from'undici'constserver=createServer()server.on('request',(req,res)=>{res.end('hello')})server.listen(0)constclient=newClient(`http://localhost:${server.address().port}`)constresponse=awaitclient.request({method: 'GET',origin: 'http://localhost:2000',path: '/'})console.log(awaitresponse.body.text())// will print 'hello'awaitserver.close() |
luddd3
commented
Dec 27, 2024
I think that it should throw an error, since it should never be the case that origin is missing. Unless it can get origin directly from |
ronag
commented
Dec 27, 2024
It should throw when a different origin is provided. Yes. |
luddd3
commented
Dec 27, 2024
I can understand from the viewpoint of backwards-compatibility, but are there other benefits for not throwing every time? I'm afraid that it encourages the wrong behavior to allow an origin, which isn't used,. I have however made a commit which does that. |
ronag
left a comment
There was a problem hiding this comment.
Still blocking. Please don't override request and instead ignore requests without origin in the dna interceptor
luddd3
commented
Dec 31, 2024
|
The only change here should be a condition in the dns interceptor and a test. |
luddd3
commented
Jan 7, 2025
So basically remove all changes so far, apply the patch your provided earlier and then write a test? |
luddd3
commented
Jan 8, 2025
IMHO that doesn't solve anything. I as a user would not expect the dns interceptor to be silently bypassed when origin wasn't provided again in my request. Everything points to |
metcoder95
commented
May 28, 2025
Gentle ping |
luddd3
commented
May 31, 2025
I don't know how to move forward since none of my proposed solutions have been accepted and I don't think the alternatives are any good. Do you have any ideas? |
metcoder95
commented
Jun 2, 2025
cc: @ronag |
I'm not sure what's wrong with my proposal? Expect origin to be passed to request, if it is passed, make sure it's same as the Pool/Client and if not passed then it's a noop for the dns interceptor. |
luddd3
commented
Jun 2, 2025
I think it is wrong that:
|
luddd3
commented
Sep 2, 2026
Fixed with #5624 |
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