-
-
Notifications
You must be signed in to change notification settings - Fork 271
Description
I would like to address the existing issues with realtime (e.g. #705, #579), particularly the problem where streams suddenly stop receiving data. I'm willing to spend some time investigating the source code and will report back if I find anything noteworthy. Since I'm not yet familiar with the repository, I would like to keep this issue as an open discussion. This will allow us to collaborate, so I can seek help if I encounter difficulties or if you believe my research is heading in the wrong direction.
If you have any additional information or thoughts on why this problem might exist, please leave a comment. Perhaps we can finally find a solution to these issues together as a community.
I'm using this repo for my local testing:
https://github.com/maxfornacon/supabase_test
I'm using latest supabase_flutter (2.6.0) and Flutter 3.24.0.
I'm running this test project on macOS as a desktop application.
The main problems I'm having with realtime in my projects for some time now is:
When the application is running for a longer period of time (e.g. desktop applications that are opened (might be in background) the whole day and don't get killed by the system) streams stop receiving new data after some time. There are no errors or exceptions thrown and the only solution I've found is to encourage the users to restart the application from time to time.
The current state of my research is that there might be a problem related to the accessToken refresh.
I've set the access token expiry time in supabase dashboard to a small value (30 seconds) and added a breakpoint in this method (realtime_client.dart):
/// Sets the JWT access token used for channel subscription authorization and Realtime RLS.
///
/// `token` A JWT strings.
void setAuth(String? token) {
accessToken = token;
for (final channel in channels) {
if (token != null) {
channel.updateJoinPayload({'user_token': token});
}
if (channel.joinedOnce && channel.isJoined) {
channel.push(ChannelEvents.accessToken, {'access_token': token});
}
}
}
This gets called every time the accessToken is refreshed and should update existing channels with the new token (that's my understanding).
I watched the channels List which contains 3 entries in the beginning for my test project. After some token refreshes this list contains < 3 entries and eventually 0 in the end. This is also when I noticed that the streams don't receive new data anymore.
I don't know yet why the channels get removed from this list but It feels not intended.
That's my current status. I'm curious about your thoughts on this.