undici icon indicating copy to clipboard operation
undici copied to clipboard

socketPath option is not passed to the connect function

Open zdm opened this issue 1 year ago • 15 comments

Bug Description

In Pool dispatcher socketPath option is not passed to the connect if connect is a function.

Reproducible By

const dispatcher = new Agent ( {
    socketPath: "/var/run/socket",
    connect ( options, callback ) {
        console.log( options );
        process.exit();
    }
} )

await fetch( "http://local/", {
    dispatcher
} );

Expected Behavior

Expecting to see socketPath in options, passed to the connect function.

When connect is specified as object - it works, but for function you just forget to pass socketPath.

Logs & Screenshots

Environment

Additional context

zdm avatar Aug 19 '24 11:08 zdm

Good catch, would you like to send a PR?

metcoder95 avatar Aug 20 '24 06:08 metcoder95

@metcoder95 Actually i doubt that this is a bug. If I read the code it looks like it was on purpose not allowed to manipulate the socketPath.

Uzlopak avatar Aug 20 '24 06:08 Uzlopak

Hmm, bit if we specify socketPath, connect function should receive if, or how it should work?

zdm avatar Aug 20 '24 06:08 zdm

Well, in theory it should, we are just not passing it to the connect factory .

We have documented that we support these options to the default connector factory. I'd also expect that they are passed down to the custom factory that its submitted.

metcoder95 avatar Aug 20 '24 06:08 metcoder95

Ok. what is your decision? I cam make PR it this is a bug.

zdm avatar Aug 20 '24 06:08 zdm

I think it should be fixed. If user do not want to change socketPath in the future - he can use closure, but by default this parameter should pass.

zdm avatar Aug 20 '24 07:08 zdm

I think a PR with the change would help us spot why we did not pass it. If it's that's the case there is likely a test to cover it.

mcollina avatar Aug 20 '24 07:08 mcollina

+1

metcoder95 avatar Aug 21 '24 07:08 metcoder95

What happens if you specify some file like /etc/passwd as socketPath?

Uzlopak avatar Aug 21 '24 10:08 Uzlopak

What happens if you specify some file like /etc/passwd as socketPath?

Error, because this is not a socket.

zdm avatar Aug 21 '24 10:08 zdm

So, I carefully looked at the code. sockerPath should behave like localAddress option. It should be removed from buildConnector options and added to the connect call options. This will be a breaking change because type script interfaces will be changed.

zdm avatar Aug 21 '24 10:08 zdm

timeout also not passed to connect function. I think all options, which are passed to the buildConnector should be passed to the connect function without exclusions.

zdm avatar Aug 21 '24 10:08 zdm

We are preparing the cut for new major, so it should be ok to do breaking changes.

Feel free to move forward with a PR so we can iterate over it

metcoder95 avatar Aug 21 '24 10:08 metcoder95

It is actually breaking if we add more options?

Uzlopak avatar Aug 21 '24 10:08 Uzlopak

I think refers to removing it from buildConnector.

Not so sure we should do that, but maybe I'm overseeing something; happy to see the PR to validate

metcoder95 avatar Aug 28 '24 08:08 metcoder95