Skip to content

Commit

Permalink
Fix IpList queries not cancelling when disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohansi committed Jul 17, 2024
1 parent f8960c8 commit 93223cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/ServerList/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void ReleaseQuery()
}
}

public void Dispose()
public virtual void Dispose()
{
ReleaseQuery();
}
Expand Down
29 changes: 16 additions & 13 deletions Facepunch.Steamworks/ServerList/IpList.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -30,15 +26,17 @@ public override async Task<bool> 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 )
{
Expand All @@ -47,9 +45,6 @@ public override async Task<bool> RunQueryAsync( float timeoutSeconds = 10 )

await list.RunQueryAsync( timeoutSeconds );

if ( wantsCancel )
return false;

Responsive.AddRange( list.Responsive );
Responsive = Responsive.Distinct().ToList();
Unresponsive.AddRange( list.Unresponsive );
Expand All @@ -64,9 +59,17 @@ public override async Task<bool> 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;
}
}
}
}

0 comments on commit 93223cb

Please sign in to comment.