mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.97k stars 519 forks source link

Requests with ".local" domain name take too long to resolve #2233

Closed KayleighYum closed 3 months ago

KayleighYum commented 3 months ago

Scope

Improves an existing behavior

Compatibility

Feature description

I recently had this issue: I was using a base url of http://example.local/ in an integration test and the test would take +- 8 seconds to resolve. After trying many different options, I changed the url to be http://example.localhost and the test resolved within the expected timeframe (+- 3 seconds).

It turns out that .local is a special host name in dns and node does a lookup for .local that doesn't resolve which then caused the tests to timeout. I proved this using the node:dns api process._getActiveRequests() This was quite time-consuming and frustrating to figure out, could this be added to the documentation as warning not to use .local urls?

kettanaito commented 3 months ago

Hi, @KayleighYum. Thanks for bringing this up.

This doesn't seem to be related to MSW though. If you are intercepting that request, no DNS lookup will be made, in the first place. If you are performing a passthrough request, it falls under how Node.js behaves, and this isn't the right place to document such behaviors.

Have you experienced this issue when you have a matching request handle for a *.local request?

KayleighYum commented 3 months ago

Hi @kettanaito, thanks for replying!

I should've made it more clear, yes this issue was occurring when I had a matching request handle for *.local. I wasn't using passthrough, I returned a HttpResponse.json({...})

kettanaito commented 3 months ago

Got it. But the mocked response was still correctly returned, no? The tests timed out due to how long it takes for the URL parser to parse the .local domain, if I'm not mistaken.

KayleighYum commented 3 months ago

That's correct, I understand your point that it's not a MSW issue, thanks for taking the time to reply!