walletconnect-monorepo: WalletConnect v2 subscriptions storage issue leading to freeze/crash

Hey,

We discovered a problem with WalletConnect v2 stored subscriptions leading to a freeze/crash. Unfortunately we haven’t yet pinpointed the exact steps to reproduce this, however we’ve gathered some data about what’s happening.

Problem

We initially spotted the issue in our Valora wallet. See https://github.com/valora-inc/wallet/issues/1215. But then noticed it’s happening on the test web app we use too: https://use-contractkit-c-labs.vercel.app/

Approximate repro steps on the web app:

  1. Go to https://use-contractkit-c-labs.vercel.app/
  2. Tap Connect
  3. Scan the QR code with Valora (note that we’ve remotely disabled WC v2 in the production versions of Valora because of this issue)
  4. Sign some things (not sure it’s needed though)
  5. Let the tab open for a while
  6. Refresh it, it will eventually crash

This is happening with @walletconnect/client 2.0.0-beta.18.

The main problem is a huge number of subscriptions end up being stored in local storage (8000+). Once the client tries to restore them in a Promise.all call when initializing, it blows up (Chrome page errors, mobile app crashes, running out of memory). https://github.com/WalletConnect/walletconnect-monorepo/blob/56db6e088d55146249788b8a27dfb9609f5f297b/packages/client/src/controllers/relayer.ts#L291-L300

Data

Here’s the data causing this (took some screenshots, but I can provide the raw data too).

You can see it’s storing 8000+ subscriptions for basically 2 different topics: Screenshot 2021-10-19 at 09 38 57

And here are the other parts of the stored state that may be of interest. Screenshot 2021-10-19 at 09 39 11 Screenshot 2021-10-19 at 09 39 16 Screenshot 2021-10-19 at 09 39 19 Screenshot 2021-10-19 at 09 39 22 Screenshot 2021-10-19 at 09 39 31

I’ve also been able to capture the logs of Valora with WalletConnect logger in trace mode.

Note that there’s a misleading log statement:

[Fri Oct 15 2021 15:47:18.275]  DEBUG    {"context": "client"} [{"context": "client/relayer"}, {"context": "client/relayer/subscription"}, "Successfully Restored subscriptions for relayer subscription"]
[Fri Oct 15 2021 15:47:18.281]  TRACE    {"context": "client"} {"context": "client/relayer"} {"context": "client/relayer/subscription"} {"method": "restore", "subscriptions": [], "type": "method"}

It says the subscriptions are empty when it was actually 8000+ items. Not sure why it doesn’t display them.

Let me know if you need any other info.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 20 (7 by maintainers)

Most upvoted comments

We had to push some fixes on top of the last release

Please use beta.26 instead

https://github.com/WalletConnect/walletconnect-monorepo/releases/tag/2.0.0-beta.26

The problem can be reproduced with 2.0.0-beta.19 😢

Using https://react-app.walletconnect.org/ (it’s using 2.0.0-beta.19, right?) and a local build of Valora where I updated to 2.0.0-beta.19.

Screenshot 2021-10-19 at 14 01 49 Screenshot 2021-10-19 at 14 06 58

Still a bit unsure of the exact steps, what I describe above still applies, but I also let the computer sleep and after I came back I directly saw the issue. This seems to indicate the WalletConnect client reconnection logic may lead to this issue.

hi @jeanregisser, so I’ve published a canary release to tackle this but because I’m struggling to reproduce it properly for testing I would appreciate if you could test it on your side

you can install the canary as follows

npm install --save @walletconnect/client@canary

OR

yarn add @walletconnect/client@canary

Additionally I made it easier to support v1.0 in parallel without using NPM aliases

npm install --save @walletconnect/legacy-client@canary

OR

yarn add @walletconnect/legacy-client@canary

Let me know what you find on your end 🙏