WalletConnect / WalletConnectSharp

A C# implementation of the WalletConnect protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting 'socket stalled' exception which causes MAUI Blazor (Android) to crash

mehrandvd opened this issue · comments

The following code throws this exception randomly:

Exception: socket stalled
at WalletConnectSharp.Common.Utils.Extensions.<WithTimeout>d__5.MoveNext()
   at WalletConnectSharp.Core.Controllers.Relayer.<>c__DisplayClass52_0.<<TransportOpen>g__Task2|2>d.MoveNext()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()

The source code:

var dappOptions = new SignClientOptions()
            {
                ProjectId = "XXXXXXXXXX",
                Metadata = new Metadata()
                {
                    Description = "Functionland Blox",
                    Icons = new[] { "https://fx.land/blox-icon.png" },
                    Name = "Functionland Blox",
                    Url = "https://fx.land/"
                },
            };

            var dappConnectOptions = new ConnectOptions()
            {
                RequiredNamespaces = new RequiredNamespaces()
                {
                    {
                        "eip155", new ProposedNamespace
                        {
                            Methods = new[]
                            {
                                "eth_sendTransaction",
                                "eth_signTransaction",
                                "eth_sign",
                                "personal_sign",
                                "eth_signTypedData",
                            },
                            Chains = new[]
                            {
                                "eip155:1"
                            },
                            Events = new[]
                            {
                                "chainChanged",
                                "accountsChanged",
                            }
                        }
                    }
                }
            };

            var dappClient = await WalletConnectSignClient.Init(dappOptions);
            // throws exception here

In Windows, it is an exception that we can catch, but in MAUI Blazor (Android) causes the app to crash even if everything is in a try-catch.

I've checked the source code and it seems it's because of this line:

await this.Provider.Connect().WithTimeout(TimeSpan.FromSeconds(5), "socket stalled");

There is a hardcoded 5-second timeout that can not be configured.