stack-auth / stack

Open-source Auth0/Clerk alternative
https://stack-auth.com
Other
3.99k stars 255 forks source link

StackAssertionError: Failed to send request - INFINITE_LOOP_DETECTED #319

Open hrmoller opened 2 weeks ago

hrmoller commented 2 weeks ago

I'm seeing the below error quite a bit in the logs on Vercel but don't see it locally at all.

I have not tracked it down to what part of my own code that provokes this error to happen but will post here when/if I track it down. However, I have the following code in my middleware.ts and I suspect that to be the place that triggers the error below.

I'm not making any direct calls to /api/v1/users/me but I call await stackServerApp.getUser() a lot of places in my application.

Versions "@stackframe/stack": "^2.6.12" "next": "14.2.15"

Error

StackAssertionError: Failed to send request to https://api.stack-auth.com/api/v1/users/me: 508 Infinite loop detected

INFINITE_LOOP_DETECTED

This is likely an error in Stack. Please make sure you are running the newest version and report it.
    at (node_modules/@stackframe/stack-shared/dist/interface/clientInterface.js:260:0)
    at (node_modules/@stackframe/stack-shared/dist/utils/results.js:122:0)
    at (node_modules/@stackframe/stack-shared/dist/interface/clientInterface.js:72:0)
    at (node_modules/@stackframe/stack-shared/dist/interface/clientInterface.js:135:0)
    at (node_modules/@stackframe/stack-shared/dist/interface/serverInterface.js:12:0)
    at (node_modules/@stackframe/stack-shared/dist/interface/serverInterface.js:22:25)
    at (node_modules/@stackframe/stack-shared/dist/interface/serverInterface.js:44:0)
    at (node_modules/@stackframe/stack/dist/esm/lib/stack-app.js:1264:0)
    at (node_modules/@stackframe/stack/dist/esm/lib/stack-app.js:120:0)
    at (node_modules/@stackframe/stack-shared/dist/utils/caches.js:43:0)
hrmoller commented 2 weeks ago

Disabling the authcheck in middleware.ts does not prevent the error from happening.

vermashobhit1994 commented 2 weeks ago

I've used chatgpt tool and find out to add below code in below path stack\packages\stack-shared\src\interface\clientInterface.ts

here add below code

// Handle loop detection (508 status code) before processing other responses
if (rawRes.status === 508) {
  return Result.error(new KnownErrors.LoopDetected(508, "Infinite loop detected in request chain"));
}

before statement

const processedRes = await this._processResponse(rawRes);