-
Notifications
You must be signed in to change notification settings - Fork 9
Error connecting to Electric: errorType: INVALID_REQUEST when pressing back button on main screen and reopening the app #23
Comments
@maloni-leonardo Thank you for reporting!
I would expect the websocket connection to close atutomatically, but your server logs are basically saying that the same device is being connected 2 times at the same time. This can happen for example when hot restarting on Web, instead of a full refresh, but we haven't seen this behavior on other platforms. |
@maloni-leonardo Here is a workaround you could use. We aren't yet sure if it's an issue in Flutter, the client or the Electric service. Easier with hooks, but you can also use useOnAppLifecycleStateChange((previous, current) {
if (current == AppLifecycleState.detached) {
electricClient.disconnect();
}
}); |
After doing more research, using a similar (native) Flutter function seems to have solved the issue! Here's the one i used: AppLifecycleListener(onDetach: () => electricClient.disconnect()); The suggested one works as well, but it requires the |
Hi again, while using the v0.7.1+4 i bumped into the same error, this time with an exception happening on sockets.dart on a Null check:
Trying to roll back to v0.7.0 still reproduce the same issue... |
@maloni-leonardo Hello! |
I'm unable to provide a proper isolate example, as the issue happens while syncing a 52M postgres table from a remote database which would be difficult to replicate, but i can provide further details such as:
|
@maloni-leonardo You might get more information by sharing the use case with the Electric team over the official Github repository or the Discord. So, from what you describe, the 52M table is properly replicated, there is no exception in the awaited |
Yes, the exception doesn't get thrown by EDIT: On a second inspection, i've found that the exception gets thrown right after it tries to reconnect to the server |
@maloni-leonardo We've added some logs in a temporary branch based on version 0.7.1+4 to the protobuf message decoding part, which might have something to do with the error you are having. Just to better organize this, is the In order to try with the new logs, you can use the following. Note that this is based on 0.7.1, so the Electric service needs to be version 0.11.x. If you are using the CLI, it will run that version automatically. dependency_overrides:
electricsql:
git:
url: https://github.com/SkillDevs/electric_dart
ref: 3c053cedcc9cae5d31af0bb34f918355551007a6
path: packages/electricsql
electricsql_cli:
git:
url: https://github.com/SkillDevs/electric_dart
ref: 3c053cedcc9cae5d31af0bb34f918355551007a6
path: packages/electricsql_cli
electricsql_flutter:
git:
url: https://github.com/SkillDevs/electric_dart
ref: 3c053cedcc9cae5d31af0bb34f918355551007a6
path: packages/electricsql_flutter |
It is related to the disconnection problem, but the "trigger" event is not related to the original issue (back button press). Here's the new log that show the issue using the dependencies overrides as requested:
|
@maloni-leonardo Thank you, that's helpful! Could you provide the server logs as well? We've included more logs related to when the disconnection happens in the client in the commit From the logs I can see the following:
|
Sorry for the huge delay, here are the requested logs: Client - using electric_dart v0.7.0 (with the dependency_overrides mentioned before)
Server - using Docker image v0.11.0
Later today i'll send the newer ones using the latest versions of the respective client and server services. UPDATE: It seems that using the latest v0.8.1 client and electric server v0.12.0 does indeed solve the issue. |
Device: Android (14)
Flutter version/SDK: Flutter 3.22.0 (stable channel)
Plugin version: Tested both on v0.6.0 and v0.7.0 versions
Issue: Running the
todos_flutter
Flutter app following the todos_electrified instructions will generate an INVALID_REQUEST error when trying to reconnect to Electric after pressing the system back button and reopening the app from background. This might be an issue on newer Android version that the app would not retain its state upon waking from sleep.Expected behaviour: After the first initialization, pressing the back button in the main screen (leaving the app running in background) and then reopening it should reconnect to Electric (like on a normal startup)
How to reproduce the issue:
After initializing the example docker and project following the README:
Stack log (client):
Stack log (server):
The text was updated successfully, but these errors were encountered: