-
Notifications
You must be signed in to change notification settings - Fork 84
Closed
Labels
Description
We experienced some memory leak when we have retry on starting a WampHost when there is socket port conflict. The logic is pretty basic: catch exception and retry after a while. Interestingly the memory leak is mostly in unmanaged code, and there are lots of handle leaks too. The handles are leaked mostly in the WampBindingHost<TMessage>.GetEventSerializer
function, stack trace as below:
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget<TInterface>(IInterceptor interceptor)
WampSharp.Core.Serialization.WampMessageSerializerFactory<TMessage>.GetSerializer<TProxy>()
WampSharp.V2.WampBindingHost<TMessage>.GetEventSerializer(IWampOutgoingRequestSerializer outgoingSerializer)
Sample code for reproducing the leak:
using System;
using System.Threading;
using WampSharp.V2;
using WampSharp.V2.Authentication;
using WampSharp.V2.Core.Contracts;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
while (true)
{
try
{
DefaultWampAuthenticationHost host = new DefaultWampAuthenticationHost($"ws://0.0.0.0:{4567}/ws", new WampSessionAuthenticatorFactory());
host.Open();
host.Dispose();
}
catch
{
Thread.Sleep(100);
GC.Collect();
}
}
}
}
internal class WampSessionAuthenticatorFactory : IWampSessionAuthenticatorFactory
{
public IWampSessionAuthenticator GetSessionAuthenticator(WampPendingClientDetails details, IWampSessionAuthenticator transportAuthenticator)
{
return new MockWampSessionAuthenticator();
}
}
internal class MockWampSessionAuthenticator : WampSessionAuthenticator
{
public override void Authenticate(string signature, AuthenticateExtraData extra)
{
}
public override string AuthenticationId => "foo";
public override string AuthenticationMethod => "bar";
}
}