-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
GoTrueClient
Memory Leak
#983
Labels
bug
Something isn't working
Comments
ghost
mentioned this issue
Feb 28, 2024
Moving to supabase/auth-js#856 for visibility and better focus. |
ghost
closed this as completed
Feb 28, 2024
This issue was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Describe the bug
Calling
createClient
results in aGoTrueClient
memory leak on React Native. It may be the entireSupabaseClient
, but I only tested withGoTrueClient
after noticing massive memory issues. See demo repo and video below.EDIT!: I have tracked the issue down to this line of code:
https://github.com/supabase/gotrue-js/blob/15c7c8258b2d42d3378be4f7738c728a07523579/src/GoTrueClient.ts#L2040
It looks like setInterval persists even after an object is dereferenced, avoiding garbage collection. Can we transfer this to @supabase/gotrue-js?
To Reproduce
I created a demo repo here. This is an extremely simplistic example; in our production app, we are using a router to navigate and noticed that (navigating between pages) we had memory leaks and supabase clients persisting, even though the page was no longer even being rendered and the supabase client should have been destroyed. I could not post our production app publicly, so I made this simple demo to show how even though I no longer have any reference to the client in my code (since it is created and destroyed after every button press), the auth client still exists and sends ticks in the background.
NOTE: as seen in the video below, after 2 button presses (and about 10 seconds) you can see log messages from two supabase clients (
GoTrueClient@0
andGoTrueClient@1
). These clients are not referenced anywhere; they were (a) created on a button press, then (b) all reference to them was lost. Garbage collection would usually take care of this (I have let it run for several minutes at a time and still had references; I've ever tried creating hundreds, losing the reference, and all hundreds of them persist for seemingly without end).Edit: I let the app run, without touching it at all, while writing this bug report (the same one shown in video, uninterrupted) and I was still seeing logs from
GoTrueClient@1
(and@0
) at2024-02-28T01:43:36.273Z
, which is quite a while after in terms of waiting for some kind of garbage collection to have kicked in (assuming there was not a memory leak, but it clearly seems like there is). Here is a log dump showing the clients persisting for quite some time (untill the process was killed): logs.txtExpected behavior
Supabase clients should not be persisting when dereferenced; somehow garbage collection is being distorted.
Screenshots
1a6a7d82-4e3e-4979-9ae7-acf2326aba62.mp4
System information
^2.39.7
The text was updated successfully, but these errors were encountered: