-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Supabase operations in onAuthStateChange will cause the next call to supabase anywhere else in the code to not return. #762
Comments
If you lower your jwt expiry time, does that also shorten the timeframe of how often this occurs? |
@izhan What "environment" is your code running in -- what browser (did you try others?), what framework, what TypeScript targets...? We generally expect to see issues reproduced with the latest version of gotrue-js before we can continue, as some of the versions you listed are known to have issues. |
Have not tried yet, can do that
Repro'd on Chrome, Safari, Firefox. Framework is ReactJS. TS target is ES2020. We've tested on New data point: we've recently downgraded back to |
@izhan did the version downgrade work? I most likely am facing the same issue in one of the edge cases: |
@aviadmini the downgrade did work for me. Similar hang here too with the newer version, but I don't see any failed network requests, do you? It seemed to be a bug in the gotrue logic, ie when to actually kickoff the call to backend |
When supabase is unreachable (e.g. local dev setup is down) there are console errors for the unsuccessful fetch and retries during a call to svelte auth helpers functions. Right after that the following call to |
We are also experiencing as similar issue when updating from supabase-js More specifically it happens, when awaiting a |
I also experienced I will of course refine the problematic supabase-js version 2.36.0 |
hey everyone, i'm trying to reproduce this so that i can figure out why it happens but i need some help here - @andreasfelix you mentioned that:
which function are you calling in @kjhughes just wondering, why do you need to call |
@kangmingtay: Thanks for investigating. You are right: Calling However, removing that call did not itself resolve the issue where another More details are available in the linked Discord chat. Note that I believe I also observed that the scenario I described above (where |
if I recall correctly any async operation that involves the supabase client, e.g. supabase.auth.onAuthStateChange(async (event, session) => {
switch (event) {
case "TOKEN_REFRESHED":
case "SIGNED_IN":
await supabase.rpc(...)
...
}
}) Our current workaround is to set a reactive variable (svelte) and run the effect whenever it changes: supabase.auth.onAuthStateChange((event, session) => {
switch (event) {
case "TOKEN_REFRESHED":
case "SIGNED_IN":
dirty.set(true)
...
}
})
dirty.subscribe(async ($dirty) => {
if ($dirty) {
dirty.set(false)
await supabase.rpc(...)
}
}) We didn't bother to look into why this works. I assume this somehow changes the order the microtasks are executed in (I am not super familiar with JS ...). |
TLDR: We are looking into a fix for this but for now the workaround is to not make async calls to postgREST / storage / edge functions using the supabase client lib inside the callback function registered in Hey everyone, it seems like this issue was introduced when this PR was merged. For context, this PR was made to address issues related to random logouts where When an async supabase call is made in the callback function in This is how the deadlock occurs. For example, if you set up a callback function in
If you make any async calls to postgREST / storage / functions using the supabase client library, it uses the custom fetch method mentioned above which requires a lock to be available. |
Thank you @kangmingtay for the update and @kjhughes for the helpful hints! Confirmed on our end too that the bug we've been experiencing was caused by this. We shipped a workaround last week to avoid the async call on TOKEN_REFRESH and no longer see these issues in prod: |
Hi, I had the issue in React Native with @supabase/supabase-js": "^2.38.4"
After getting some advice from @GaryAustin1 on discord. I removed all the functions inside onAuthStateChange functions and put them in another function, and made a single call. The code looked like this now and works fine. Note, all the logic was moved to external function "handleUserUpdates()"
It seems after auth state change, any immediate supabase database calls hang after that. In my case, the auth.updateUser() function would not return a response. Hopefully this helps someone. |
I just edited the title of this issue to reflect the root problem so users might spot it quicker. This bug is causing users major loss of time as it is not documented you can't make calls in onAuthStateChange and the symptom they see is in a completely different part of code. This should be documented in the docs and fixed or addressed as soon as possible. It is a multi-hour loss of time for users trying to figure out and/or reaching out for help. |
Big ups to OP we have this problem too m8 |
@GaryAustin1 Can you point to where you would want this to be present in docs. Trust me, I've tried to address the issue on a technical level -- unfortunately it's not possible because of JavaScript, browsers, NextJS and all the other runtimes. Alternatively, we can maybe turn off the await handling or make it configurable. Please let me know what works best for you. |
@hf It should be documented here https://supabase.com/docs/reference/javascript/auth-onauthstatechange at least to not make supabase calls in that function handler and what happens if you do. I added a note in troubleshooting https://github.com/orgs/supabase/discussions/19058 awhile back that I can clean up as it says "until this is fixed". Not sure the user suggestion above to move calls to a function is the recommended way to avoid this or not: supabase.auth.onAuthStateChange(async (event, session) => {
console.log(`Supabase auth event is ${event}`);
dispatch(setUserSession(session));
dispatch(setUser(session?.user ?? null));
// Call the function to handle user updates
handleUserUpdates(dispatch, session);
}) |
Docs changes here: supabase/supabase#19902 |
I removed my onAuthStateChange code and still have getSession hang on supabase-js 2.39.2 |
I can confirm this is working see my comment nuxt-modules/supabase#273 (comment) |
I found that you have to call every function for auth (signIn, signOut, ...) in client-side code (using a client supabase) in order for it to work properly. |
Bug report
Describe the bug
await supabase.auth.getSession()
will hang indefinitely every hour or so, until the user reloads the page. We suspect it's related to the token needing to be refreshed.To Reproduce
await supabase.auth.getSession()
getSession
will hang indefinitelyIt's unclear right now whether (4) happens all the time or only some of the time. But we've been managing to reproduce pretty frequently, both locally and in prod. It's been affecting our customers as well.
Reloading the browser after (4) will immediately resolve the issue. Subsequent reloads will be fine, until an hour of inactivity in which this problem occurs again.
We've tried multiple versions of supabase-js and gotrue already, to no effect. This has been occurring for the past few weeks.
supabase/supabase#15930 seems related but that ticket seems to be concerned with immediately after Google OAuth. Our problem occurs well after initial login.
Expected behavior
We expect
getSession
to never hang indefinitelyScreenshots
If applicable, add screenshots to help explain your problem.
System information
Additional context
We tried this on multiple versions of supabase-js (2.24, 2.26, 2.31) and gotrue (2.42, 2.43.1, 2.46.1)
The text was updated successfully, but these errors were encountered: