electric icon indicating copy to clipboard operation
electric copied to clipboard

expo android app cant connect to the electric service after first hot reload

Open wildsylvan opened this issue 11 months ago • 2 comments

the sync service says:

07:11:37.098 pid=<0.3160.0> [info] GET /ws
07:11:37.100 pid=<0.3160.0> instance_id=11d59e1b-bd78-4615-81eb-0e8ff2e90ec5 [info] Sent 101 in 1ms
07:11:38.157 pid=<0.3160.0> client_id=c07a6aba-f79f-43ea-9569-a05003726f79 instance_id=11d59e1b-bd78-4615-81eb-0e8ff2e90ec5
[info] attempted multiple connections from the same client

the debug log on the client:

 INFO  Using SQLite version: 3.42.0
 INFO  retrieved lsn 51,52,55,50,49,54,48,48
 INFO  connecting to electric server
 LOG  [rpc] send: #SatAuthReq{id: c07a6aba-f79f-43ea-9569-a05003726f79, token: eyJhbGciOiJub25lIn0.eyJzdWIiOiI0ZTM2MTQ4MS0xYzZkLTQxMjUtYTAzMy1iYzQ4NjEwMzA1OGUifQ.}
 LOG  [proto] send: #SatRpcRequest{method: authenticate, requestId: 1}
 LOG  [proto] recv: #SatRpcResponse{method: authenticate, requestId: 1, error: #SatErrorResp{type: INVALID_REQUEST}}
 WARN  RPC call authenticate/1 failed with #SatErrorResp{type: INVALID_REQUEST}
 LOG  server returned an error while establishing connection: undefined
 LOG  connectAndStartRetryHandler was cancelled: undefined
 LOG  connectAndStartRetryHandler was cancelled: undefined

before trying to reload the app from the expo cli, it works. after the reload, you have to restart the electric sync service to make it work again

wildsylvan avatar Mar 11 '24 19:03 wildsylvan

I will be looking into this - for the time being I think that doing full reloads rather than hot reloads should work - you can disable fast refresh from the developer menu: Screenshot 2024-03-28 at 12 41 26

If the issue persists with regular reloads as well let me know - also it'd be good to know if you experience this issue with the expo example or with your own project.

msfstef avatar Mar 28 '24 10:03 msfstef

@msfstef I seem to also be getting this on the web, even after a complete browser close-reopen. It seems that the server process might not be cleaning out sessions or something. In any case, currently the only solution is to completely remove all data from the browser and reinit from scratch, or kill and relaunch the server process. That is a huge PITA.

AntonOfTheWoods avatar May 25 '24 03:05 AntonOfTheWoods

@AntonOfTheWoods Maybe this is related? There seems to be unreleased connections in the server too. https://discord.com/channels/933657521581858818/1240698235262337103/1240698237992833065

The workaround in Flutter Android is to call disconnect when the app is getting shut down.

https://github.com/SkillDevs/electric_dart/issues/23

davidmartos96 avatar May 25 '24 08:05 davidmartos96

👋 we've been working the last month on a rebuild of the Electric server over at a temporary repo https://github.com/electric-sql/electric-next/

You can read more about why we made the decision at https://next.electric-sql.com/about

We're really excited about all the new possibilities the new server brings and we hope you'll check it out soon and give us your feedback.

We're now moving the temporary repo back here. As part of that migration we're closing all the old issues and PRs. We really appreciate you taking the time to investigate and report this issue!

KyleAMathews avatar Aug 06 '24 13:08 KyleAMathews