-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: server side fetch requests made to various endpoints #742
Comments
I absolutely agree with you, it is quite wasteful to make full-blown http requests in Node side. What I don't understand, however, is that we are already using nuxt-auth/src/runtime/utils/fetch.ts Lines 5 to 24 in adfe97e
I guess we'd have to refer to the |
Awesome, thank you @phoenix-ru! While looking into this I came up with two possible reasons.
|
So after looking into this it turns out the fetch implementation does indeed prepend the entire host section of the URL. This causes I've played with it for a bit and technically all that's needed is a change in the fetch constructor. -> warflash/nuxt-auth-debug@746cfd8 To show the differences and debug I went ahead and created cpu flamegraphs for both versions. Default/Current version:Notice the fetch call and http dispatch. Full cpuprofile: Patched version based on repo linked:Notice the localFetch working and only calling Full cpuprofile: Obviously on localhost those changes only shave off .2ms, however in a real env they save an entire roundtrip that would otherwise have been routed out to the public internet and back to the nuxt app. |
Hi @warflash, thank you a lot for a thorough investigation, I can indeed confirm the issue exists. Moreover, it is caused by this particular line in Nuxt's I checked your linked repo, however, I don't think I can use it, since the issue is really in It uses nuxt-auth/src/runtime/utils/url.ts Line 8 in 949e556
nuxt-auth/src/runtime/composables/commonAuthState.ts Lines 35 to 38 in 949e556
and, finally, computed state Lines 117 to 119 in 949e556
Line 128 in 949e556
So, going back to the But there may be much better solutions, so all the ideas are welcome. I have seen quite a lot of confusion when it comes to origin, baseURL, pathname and other related things:
Even though there was |
Oh I apologize, for some reason my linked commit was faulty and didn't include the actual "fix"/workaround. But yeah, And I highly agree with your concerns regarding I feel like it should for sure be included somewhere in the path building logic -> #340 Just from an minimal implementation perspective I feel like this logic: warflash/nuxt-auth-debug@746cfd8 should already work for most things. In fact we've been using a patched version with that logic for 2 weeks now on our clusters and everything is smooth so far. It still requires the possibility the overwrite the hardcoded |
Okay, I see it now:
@warflash Regarding |
@warflash wow, thanks for reporting this issue! I can already see 50% improvement on req/sec when stress-tested on a local machine (and similar flamegraph results as yours). |
Great you're seeing the same sort of improvements, nice!
Would there be a way for me to install a prerelease of that PR or should I go ahead and create a pnpm patch myself? |
I will ask @zoey-kaiser to do a prerelease as a part of her functional review. |
I will do it right now! ❤️ |
Just released the changes in a We will also begin testing the improvements internally and include it in the next full 0.8.0 release! Thank you so much for bringing this issue to our attention and the amazing investigation! We really appreciate it ❤️ |
@zoey-kaiser I'm currently testing upgrade from 0.7.2 to 0.8.0-rc This break my config : local provider and auth.baseURL defined to a custom base url ex : https://example.com/ Login is posted to the nuxt base URL , not to my custom base url I have to redefine all the endpoints and removing the / prefix .
|
Hi @spras 👋 Could you please open a new issue for this! I will look into it tomorrow! 😊 |
Environment
Reproduction
https://github.com/warflash/nuxt-auth-debug
Using the module's
playground-authjs
dir.Describe the bug
In our production env we noticed a ton of
/api/auth/session?callbackUrl=http:%2F%2Flocalhost:3333%2Falways-unprotected
requests coming through our proxy layer, all with user agent set to "node".To debug this I spun up a local version of the playground of the repo and attached a proxy, -> see repro above.
I am not logged in on the local playground, depite that:
In the logs below you can see me calling for
/always-unprotected
with my browsers user agent in the first line.Then 3 requests are fired for
/api/auth/session?callbackUrl=http:%2F%2Flocalhost:3333%2Falways-unprotected
(which is what we've been seeing in our prod proxy logs as well, followed by/api/auth/providers
and/api/auth/csrf
.Additional context
Wanted to perhaps spark a discussion or question on whether these calls can be avoided or made internally using $fetch or at least limited to users that are actually logged in or pages that are protected. Sending out a full http request for all of these adds a considerable amount of overhead and delay to the rendered SSR page.
Logs
The text was updated successfully, but these errors were encountered: