public override void ChannelWritabilityChanged(IChannelHandlerContext context) { PendingWriteQueue queue = _queueRef.Value; IByteBuffer msg = (IByteBuffer)queue.Current; if (msg is null) { return; } Assert.Equal(1, msg.ReferenceCount); // This call will trigger another channelWritabilityChanged() event because the number of // pending bytes will go below the low watermark. // // If PendingWriteQueue.remove() did not remove the current entry before triggering // channelWritabilityChanged() event, we will end up with attempting to remove the same // element twice, resulting in the double release. queue.Remove(); Assert.Equal(0, msg.ReferenceCount); }