WebSocket disconnection after background for some time
Opened this issue · 11 comments
Hi, I noticed that automatic reconnection after closing app or refreshing the state is not that effective. For trust wallet connection, it takes a little time to reconnect when you come back to the app, but for metamask and exodus wallet, it hardly reconnects. I've tested this in 4 different andriod devices and 2 ios. Also, metamask hardly connects using the wallet icon interface, but for qrcode, it connects perfectly.
Please if you'd update the persistent session or automatic reconection, it would be highly appreciated. Also if you can add support for formatting bigint and ethers conversion of units, that would go a long way. Outside these, Reown works perfectly fine and better with the [1.1.0-beta02] release.
I am experiencing the same issue. When the Flutter app goes into the background (onPause), and we send a request to connect to MetaMask, it seems that the WebSocket connection (relay) disconnects automatically after a few seconds. This prevents the request from completing successfully.
For instance, when trying to connect our dapp to MetaMask, we initiate the connection request, and MetaMask opens as expected. However, since the user needs to wait for the "Approve" button to appear, the WebSocket may disconnect during this wait time. Once the user hits "Approve" and returns to the Flutter dApp, the app does nothing and shows a "Try Again" button. This issue occurs about 90% of the time.
Closed by client with code 1006 .
Thanks both for the reports, I'll be taking a look at them. I understand @AliAzizi report but not so much your's @Sleechigo... If you could both share a demo video I'd highly appreciate as we had never been reported of such issues.
As per the WebSocket disconnection I'm lost there as disconnection shouldn't happen that quick and, in fact, I can't reproduce it even with the link conditioner set to High Latency so I might need some more help discovering the issue.
Hello @Sleechigo @AliAzizi! If you could provide clear steps to reproduce this it would help me a lot!
Hello @quetool! I have experienced a similar problem when testing the SDK. The way @AliAzizi describes it, when the app is in background the relay disconnects.
I could reproduce the bug in the example appkit project reown_flutter/packages/reown_appkit/example/base
. However, to start the project I needed to add this to the pubspec.yaml
since the pinenacl 0.5.1 refused to wotk as is:
dependency_overrides:
pinenacl: 0.6.0
Here is the log: https://pastecode.io/s/pbja4s1a
Here is the screencast: https://disk.yandex.ru/i/uSaOlzrlT1Ri6w. Ran it on OnePlus 5T, Android 15. Also put a blue overlay when entering the password.
UPD
Researching the bug led me to where the error is thrown, that is WebSocketHandler
, 65th line on await _socket!.ready;
, the error is SocketException: Failed host lookup: 'relay.walletconnect.org' (OS Error: No address associated with hostname, errno = 7)
.
The reconnection is triggered by the Peer jsonRPC
when the app is in background with the 1002 eror code, it calls the _handleRelayClose
. I coulnd't find enough info on the Internet about this error, but it seems like the WebSocketChannel cannot hold the connection while in background. Though it's just my assumption.
So the minimal reproducible example is to open the example app, wait till the connection is established, and then put the app in the background.
This is wonderful report @xdkomel, thank you very much! I'll try to make some time to investigate. Do you mind me asking how much time passes before the issue arise? We didn't have this issue before with WebSockeChannel package...
Any news on this? Currently we don't have a working android version of the sdk as I understand?
Can you all confirm that is happening only on Android @AliAzizi @Sleechigo @xdkomel @haykgalstyan ?
Some more details you can share?
Device model?
Type of connection?
Android version?
Are you running the example/base folder or directly trying the SDK as dependency? If the latter, which version?
I am experiencing the same issue. When the Flutter app goes into the background (onPause), and we send a request to connect to MetaMask, it seems that the WebSocket connection (relay) disconnects automatically after a few seconds. This prevents the request from completing successfully.
For instance, when trying to connect our dapp to MetaMask, we initiate the connection request, and MetaMask opens as expected. However, since the user needs to wait for the "Approve" button to appear, the WebSocket may disconnect during this wait time. Once the user hits "Approve" and returns to the Flutter dApp, the app does nothing and shows a "Try Again" button. This issue occurs about 90% of the time.
Closed by client with code 1006 .
This comment perfectly describes my issue. (besides error message)
Maybe something tied to android lifecycle and pausing of the connection.
My device is a pixel8 updated to the latest version of android.
I use it as a dependency, It worked for a long time, then suddenly stopped some time after Reown migration.
I dont use SIWE if this helps reproduce the issue. Just basic connecting to wallet.
Here's my initialization code if it could help
appkit.ReownAppKitModal(
context: context.as<BuildContext>(),
projectId: _config.projectId,
metadata: appkit.PairingMetadata(
name: _config.appInfo.name,
description: _config.appInfo.description,
url: _config.appInfo.url,
icons: [_config.appInfo.iconUrl],
redirect: appkit.Redirect(
native: _config.appInfo.redirectNativeScheme,
),
),
requiredNamespaces: {
'eip155': appkit.RequiredNamespace(
chains: _config.requiredChains,
methods: _config.requiredMethods,
events: _config.requiredEvents,
),
},
enableAnalytics: false,
logLevel: _loggingEnabled ? appkit.LogLevel.all : appkit.LogLevel.nothing,
).init();
Seems to be different reasons of closing the connection, @xdkomel is getting 1002 while the others are getting 1006. I'll investigate and update this thread. @haykgalstyan do you remember last time/version that it used to work?
I don't remember, but I can do the testing if that will help us solve this @quetool.