DotNetty icon indicating copy to clipboard operation
DotNetty copied to clipboard

channel.CloseCompletion.ContinueWith not working (unity3d)

Open Theleruby opened this issue 5 years ago • 0 comments

Currently in the process of porting some working code from Netty to DotNetty to use in my Unity game. Unity version I'm using is 2018.3.8f1 with following configuration:

Scripting Runtime Version = .NET 4.x Equivalent Scripting Backend = Mono API compatibility level = .NET 4.x

Things seem to be working for the most part but I found a weird issue.

Here you can see the original code for Netty and my attempt at porting to DotNetty:

ChannelFuture connectionFuture = bootstrap.connect("127.0.0.1", 12345);
connectionFuture.addListener(new GenericFutureListener<ChannelFuture>()
{
	@Override
	public void operationComplete(ChannelFuture future) throws Exception
	{
		if (future.isSuccess())
		{
			future.channel().closeFuture().addListener(new GenericFutureListener<ChannelFuture>()
			{
				@Override
				public void operationComplete(ChannelFuture future) throws Exception
				{
					System.out.println("Channel closed");
				}
			});
		}
		else
		{
			System.out.println("Connection failed");
		}
	}
});
Task<IChannel> connectionTask = bootstrap.ConnectAsync("127.0.0.1", 12345);
connectionTask.ContinueWith(delegate(Task<IChannel> task)
{
	if (task.IsFaulted || task.IsCanceled)
	{
		Debug.Log("Connection failed");
	}
	else
	{
		task.Result.CloseCompletion.ContinueWith(delegate(Task task1)
		{
			Debug.Log("Channel closed");
		});
	}
});

In both instances when the channel closes after a successful connection I expect to see printed "Channel closed". The Netty code works just fine, but with DotNetty this never prints. This leads me to believe the CloseCompletion is never being run. Seems like a bug to me.

As a workaround, I was able to attach my channel close behaviour to a ChannelHandlerAdapter which overrides ChannelInactive instead, so this issue isn't blocking me from working on my game, but I figured I should report it anyway.

Theleruby avatar Apr 13 '19 17:04 Theleruby