peterldowns / localias

custom local domain aliases for local dev servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Significant delay in request handling

taylorthurlow opened this issue · comments

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:

  • Pinging the localias domains correctly resolve to 127.0.0.1 and there is no delay
  • macOS Sonoma, M3 Pro Mac Mini
  • 2.0.1+commit.c358250

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:

  • What are the aliases you're using? (localias list, localias debug config --print)
  • What are the logs you see when you start localias? (localias run)
  • What's your hostname? (hostname)
  • Do you have the same problem with a different backend service, like a simple python file server? (python3 -m http.server 8888 to run a server on port 8888)

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

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.

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!

@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

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.

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