kotlin-walletconnect-lib icon indicating copy to clipboard operation
kotlin-walletconnect-lib copied to clipboard

WCSessionStore APIs are not async friendly.

Open prashanOS opened this issue 2 years ago • 2 comments

Hi from OpenSea! We have found an issue when enabling Android's StrictMode. It fails because FileWCSessionStore is doing file I/O on the main thread.

The WCSessionStore's methods are all synchronous, but a store (unless it is purely in-memory) is by nature asynchronous. In general, this means implementations would have to block the current thread while doing either file or network I/O. store() and remove() methods could maybe be implemented as fire-and-forget methods, but then we lose access to Kotlin's built-in structured concurrency.

With the provided FileWCSessionStore implementation, this means we are blocking the main thread while doing file I/O whenever these methods are called. FileWCSessionStore is also doing file I/O on the main thread in its' init block.

The proposed solution would be to make these methods suspend functions. Then, consumers can use their own coroutine scope to run these methods. This does mean that WCSession would need to take in a coroutine scope to launch these new suspend functions from.

prashanOS avatar Apr 26 '22 19:04 prashanOS

@prashanOS try this, let me know if you have issues

jemshit avatar Sep 21 '22 09:09 jemshit

Hey guys, i see you're trying to improve this library, i have written it from scratch using coroutines, you could try it instead. We're already using it in prod.

@prashanOS @mhernand40 @matthewrkula

jemshit avatar Oct 03 '22 07:10 jemshit