fix: Fixes issue with wepoll losing GCHandle. (#1039)

- [X] Fixes issue with wepoll losing GCHandle.
- [X] `NetState.Disconnect()` is no longer thread safe.
  - Use `Core.LoopContext.Post()` to post disconnects
- [X] Optimizes PollGroup by not processing IntPtr -> GCHandle for discard polls.
This commit is contained in:
Kamron Batman 2022-05-30 14:04:54 -07:00 committed by GitHub
parent d261973cee
commit aeec7f78fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 25 deletions

View file

@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Server.Network;
using Xunit;
namespace Server.Tests.Network;
public class PollGroupTests
{
[Fact]
public void TestPollGroup()
{
// var group = new KQueuePollGroup();
var nss = new NetState[2048];
var handles = new IntPtr[2048];
for (var i = 0; i < nss.Length; i++)
{
nss[i] = PacketTestUtilities.CreateTestNetState();
handles[i] = (IntPtr)nss[i].Handle;
}
GC.AddMemoryPressure(10000000000);
GC.Collect();
GC.RemoveMemoryPressure(10000000000);
GC.Collect();
Thread.Sleep(1000);
for (var i = 0; i < nss.Length; i++)
{
Assert.Equal(nss[i].Handle, (GCHandle)handles[i]);
}
// group.Dispose();
}
}