Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.09k stars 977 forks source link

ChannelOutboundBuffer Remove0 SafeSetFailure twice? #276

Closed caozhiyuan closed 6 years ago

caozhiyuan commented 7 years ago
    /// <summary>
    ///     Will remove the current message, mark its {@link ChannelPromise} as failure using the given {@link Exception}
    ///     and return {@code true}. If no   flushed message exists at the time this method is called it will return
    ///     {@code false} to signal that no more messages are ready to be handled.
    /// </summary>
    public bool Remove(Exception cause) => this.Remove0(cause, true);

    bool Remove0(Exception cause, bool notifyWritability)
    {
        Entry e = this.flushedEntry;
        if (e == null)
        {
            this.ClearNioBuffers();
            return false;
        }
        object msg = e.Message;

        TaskCompletionSource promise = e.Promise;
        int size = e.PendingSize;

        this.RemoveEntry(e);

        if (!e.Cancelled)
        {
            // only release message, fail and decrement if it was not canceled before.
            ReferenceCountUtil.SafeRelease(msg);

            Util.SafeSetFailure(promise, cause, Logger);
            if (promise != TaskCompletionSource.Void && !promise.TrySetException(cause))
            {
                Logger.Warn($"Failed to mark a promise as failure because it's done already: {promise}", cause);
            }
            this.DecrementPendingOutboundBytes(size, false, notifyWritability);
        }

        // recycle the entry
        e.Recycle();

        return true;
    }
nayato commented 7 years ago

@caozhiyuan do you have any more data as to when that happens?

caozhiyuan commented 7 years ago

@nayato when transport send data (AbstractChannel Flush0 channel.DoWrite) error will raise this .

caozhiyuan commented 7 years ago

@nayato there real has a problem. https://github.com/Azure/DotNetty/blob/dev/src/DotNetty.Transport/Channels/ChannelOutboundBuffer.cs#L238-L242