diff --git a/src/DotNetty.Codecs.Http/HttpServerKeepAliveHandler.cs b/src/DotNetty.Codecs.Http/HttpServerKeepAliveHandler.cs index cbec7c65c..aae9166bc 100644 --- a/src/DotNetty.Codecs.Http/HttpServerKeepAliveHandler.cs +++ b/src/DotNetty.Codecs.Http/HttpServerKeepAliveHandler.cs @@ -52,7 +52,9 @@ public override ValueTask WriteAsync(IChannelHandlerContext context, object mess } if (message is ILastHttpContent && !this.ShouldKeepAlive()) { - return new ValueTask(base.WriteAsync(context, message).CloseOnComplete(context)); + Task task = base.WriteAsync(context, message).AsTask(); + task.CloseOnComplete(context.Channel); + return new ValueTask(task); } return base.WriteAsync(context, message); }