peterldowns / localias

custom local domain aliases for local dev servers
MIT License
605 stars 3 forks source link

Significant delay in request handling #21

Closed taylorthurlow closed 7 months ago

taylorthurlow commented 7 months ago

All 7 or 8 of the applications I've added to localias so far are functioning, but have this weird quirk where certain requests take an extra 4-5 seconds to actually "start doing anything". The application receiving the request makes no acknowledgement of receiving the request until the very end, at which point the response happens in milliseconds, so it does seem like something in localias/caddy is getting hung up (or mDNS or something).

The extra detail that makes this a little more confusing is that the problem disappears temporarily when serving an app through a web browser. The initial request to the application has this large up-front delay, and then after the first page loads, things are as snappy as a direct connection. After a few minutes of inactivity, a subsequent request has the same up-front delay, then back to being quick.

I use a desktop application that sends queries to one of the services I have set up, and that service behaves as I describe above in a web browser, but when sending requests to it from this separate application, all requests have an up-front delay, and there is no "warm cache" effect happening. I suppose this would mean that the browser is doing something that the application is not. The application in question is actually an electron app, and I'm using a Chrome-based browser, so they are more similar than not.

Let me know if this is a clear explanation, my head is still not on straight this morning.

Other notes:

peterldowns commented 7 months ago

Interesting — I'm not sure exactly what's going on, but I wouldn't be surprised if it's a problem with localias.

Can you tell me:

Apologies for the trouble, I'm sorry that Localias isn't working for you out of the box.

taylorthurlow commented 7 months ago

No apologies necessary, thanks for following up.

taylor@cintra:~/ % localias list
order-api.local -> 4000
bayos.local -> 4001
wos.local -> 4002
integrations.local -> 4003
my.local -> 4004
machine.local -> 4005
metalprints.local -> 4006
customer-api.local -> 4007
# localias config file syntax
#
#       alias: port
#
# for example,
#
#   bareTLD: 9003 # serves over https and http
#   implicitly_secure.test: 9002 # serves over https and http
#   https://explicit_secure.test: 9000 # serves over https and http
#   http://explicit_insecure.test: 9001 # serves over http only
#
order-api.local: 4000
bayos.local: 4001
wos.local: 4002
integrations.local: 4003
my.local: 4004
machine.local: 4005
metalprints.local: 4006
customer-api.local: 4007
taylor@cintra:~/ % hostname
cintra.local

After setting up a python3 web server with python3 -m http.server 4000 so I can access it with the alias set up as order-api.local:

taylor@cintra:Temp/ % time curl localhost:4000
Hello, world
curl localhost:4000  0.00s user 0.00s system 47% cpu 0.008 total

taylor@cintra:Temp/ % time curl https://order-api.local
Hello, world
curl https://order-api.local  0.01s user 0.01s system 0% cpu 5.061 total

The above curl request to https://order-api.local does not exhibit the same browser behavior where there is an apparent warm cache on subsequent requests. Subsequent curl requests consistently take 5 seconds and change.

The time results above really do make me think there is a 5 second timeout happening somewhere.

peterldowns commented 7 months ago

Thank you for the quick response — I am pretty sure I know what the problem is now. To confirm, can you please share the logs that localias emits when you run localias run and then make a few requests?

My suspicion is that the mDNS server is not able to start because your hostname ends in .local, as reported in #20. On macOS, requests to .local domains will still result in an mDNS request; without the server running to serve a response, this request times out, which explains the initial 5 second delay. For more information you can hunt around on stackoverflow, here's a similar report.

Basically, requests to .local domains are slow on macOS if the mDNS responder isn't running. I'll have a bugfix pushed soon. Sorry again, and thanks for reporting it!

peterldowns commented 7 months ago

@taylorthurlow should be fixed now — if you installed via brew, you can brew upgrade localias to receive version 2.0.2+commit.56d660e. When you localias run you should see that the mDNS server starts successfully and emits some log lines like

mDNS: serving order-api.local
mDNS: serving bayos.local
mDNS: serving wos.local
mDNS: serving integrations.local
mDNS: serving my.local
mDNS: serving machine.local
mDNS: serving metalprints.local
mDNS: serving customer-api.local
taylorthurlow commented 7 months ago

Working wonderfully now, thank you. And my apologies for missing the fact that you had asked for localias run output, I clearly skipped over that before.

peterldowns commented 7 months ago

Sweet, thanks for confirming. Enjoy! If you run into any other issues or have other feature requests, please open more issues 🫡