From 6f203abc2113cf930908a1dac2fa8dce177b822a Mon Sep 17 00:00:00 2001 From: skibitsky Date: Thu, 9 Nov 2023 12:42:15 +0900 Subject: [PATCH] fix: relayer reconnects on disposal --- WalletConnectSharp.Core/Controllers/Relayer.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/WalletConnectSharp.Core/Controllers/Relayer.cs b/WalletConnectSharp.Core/Controllers/Relayer.cs index 219fa8d..62e6aa7 100644 --- a/WalletConnectSharp.Core/Controllers/Relayer.cs +++ b/WalletConnectSharp.Core/Controllers/Relayer.cs @@ -230,13 +230,15 @@ protected virtual void RegisterProviderEventListeners() protected virtual void RegisterEventListeners() { - this.OnConnectionStalled += async (sender, args) => - { - if (this.Provider.Connection.IsPaused) - return; + this.OnConnectionStalled += OnConnectionStalledHandler; + } - await this.RestartTransport(); - }; + private async void OnConnectionStalledHandler(object sender, EventArgs e) + { + if (this.Provider.Connection.IsPaused) + return; + + await this.RestartTransport(); } protected virtual async void OnProviderPayload(string payloadJson) @@ -499,6 +501,9 @@ protected virtual void Dispose(bool disposing) if (disposing) { + _transportExplicitlyClosed = true; + this.OnConnectionStalled -= OnConnectionStalledHandler; + Subscriber?.Dispose(); Publisher?.Dispose(); Messages?.Dispose();