From 93223cb30ac878e691dbd72fa0bfb2e1567fa3c3 Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Tue, 16 Jul 2024 22:07:37 -0400 Subject: [PATCH] Fix IpList queries not cancelling when disposed --- Facepunch.Steamworks/ServerList/Base.cs | 2 +- Facepunch.Steamworks/ServerList/IpList.cs | 29 +++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Facepunch.Steamworks/ServerList/Base.cs b/Facepunch.Steamworks/ServerList/Base.cs index 3a6cfbd..caf7089 100644 --- a/Facepunch.Steamworks/ServerList/Base.cs +++ b/Facepunch.Steamworks/ServerList/Base.cs @@ -135,7 +135,7 @@ void ReleaseQuery() } } - public void Dispose() + public virtual void Dispose() { ReleaseQuery(); } diff --git a/Facepunch.Steamworks/ServerList/IpList.cs b/Facepunch.Steamworks/ServerList/IpList.cs index c76e88c..aa7412b 100644 --- a/Facepunch.Steamworks/ServerList/IpList.cs +++ b/Facepunch.Steamworks/ServerList/IpList.cs @@ -1,9 +1,5 @@ -using Steamworks.Data; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using System.Threading.Tasks; namespace Steamworks.ServerList @@ -30,15 +26,17 @@ public override async Task RunQueryAsync( float timeoutSeconds = 10 ) var ips = Ips.ToArray(); - while ( true ) + wantsCancel = false; + + while ( !wantsCancel ) { - var sublist = ips.Skip( pointer ).Take( blockSize ); - if ( sublist.Count() == 0 ) + var sublist = ips.Skip( pointer ).Take( blockSize ).ToList(); + if ( sublist.Count == 0 ) break; using ( var list = new ServerList.Internet() ) { - list.AddFilter( "or", sublist.Count().ToString() ); + list.AddFilter( "or", sublist.Count.ToString() ); foreach ( var server in sublist ) { @@ -47,9 +45,6 @@ public override async Task RunQueryAsync( float timeoutSeconds = 10 ) await list.RunQueryAsync( timeoutSeconds ); - if ( wantsCancel ) - return false; - Responsive.AddRange( list.Responsive ); Responsive = Responsive.Distinct().ToList(); Unresponsive.AddRange( list.Unresponsive ); @@ -64,9 +59,17 @@ public override async Task RunQueryAsync( float timeoutSeconds = 10 ) return true; } + // note: Cancel doesn't get called in Dispose because request is always null for this class public override void Cancel() { wantsCancel = true; } + + public override void Dispose() + { + base.Dispose(); + + wantsCancel = true; + } } -} \ No newline at end of file +}