Esempio n. 1
0
        protected override void OnRequestProcessingEnded()
        {
            try
            {
                // https://tools.ietf.org/html/rfc7540#section-8.1
                // If the app finished without reading the request body tell the client not to finish sending it.
                if (!EndStreamReceived && !RstStreamReceived)
                {
                    Log.RequestBodyNotEntirelyRead(ConnectionIdFeature, TraceIdentifier);

                    var states = ApplyCompletionFlag(StreamCompletionFlags.Aborted);
                    if (states.OldState != states.NewState)
                    {
                        // Don't block on IO. This never faults.
                        _ = _http2Output.WriteRstStreamAsync(Http2ErrorCode.NO_ERROR);
                        RequestBodyPipe.Writer.Complete();
                    }
                }

                _http2Output.Dispose();

                RequestBodyPipe.Reader.Complete();

                // The app can no longer read any more of the request body, so return any bytes that weren't read to the
                // connection's flow-control window.
                _inputFlowControl.Abort();

                Reset();
            }
            finally
            {
                _context.StreamLifetimeHandler.OnStreamCompleted(this);
            }
        }
        private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error)
        {
            if (!TryApplyCompletionFlag(StreamCompletionFlags.Aborted))
            {
                return;
            }

            Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason);

            // Don't block on IO. This never faults.
            _ = _http2Output.WriteRstStreamAsync(error);

            AbortCore(abortReason);
        }
Esempio n. 3
0
        private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error)
        {
            if (Interlocked.Exchange(ref _requestAborted, 1) != 0)
            {
                return;
            }

            Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason);

            // Don't block on IO. This never faults.
            _ = _http2Output.WriteRstStreamAsync(error);

            AbortCore(abortReason);
        }
Esempio n. 4
0
        public void CompleteStream(bool errored)
        {
            try
            {
                // https://tools.ietf.org/html/rfc7540#section-8.1
                // If the app finished without reading the request body tell the client not to finish sending it.
                if (!EndStreamReceived && !RstStreamReceived)
                {
                    if (!errored)
                    {
                        Log.RequestBodyNotEntirelyRead(ConnectionIdFeature, TraceIdentifier);
                    }

                    var(oldState, newState) = ApplyCompletionFlag(StreamCompletionFlags.Aborted);
                    if (oldState != newState)
                    {
                        Debug.Assert(_decrementCalled);

                        // If there was an error starting the stream then we don't want to write RST_STREAM here.
                        // The connection will handle writing RST_STREAM with the correct error code.
                        if (!errored)
                        {
                            // Don't block on IO. This never faults.
                            _ = _http2Output.WriteRstStreamAsync(Http2ErrorCode.NO_ERROR);
                        }
                        RequestBodyPipe.Writer.Complete();
                    }
                }

                _http2Output.Complete();

                RequestBodyPipe.Reader.Complete();

                // The app can no longer read any more of the request body, so return any bytes that weren't read to the
                // connection's flow-control window.
                _inputFlowControl.Abort();

                // We only want to reuse a stream that has completely finished writing.
                // This is to prevent the situation where Http2OutputProducer.ProcessDataWrites
                // is still running in the background.
                CanReuse = !_keepAlive && HasResponseCompleted;
            }
            finally
            {
                _context.StreamLifetimeHandler.OnStreamCompleted(this);
            }
        }
        private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error)
        {
            var states = ApplyCompletionFlag(StreamCompletionFlags.Aborted);

            if (states.OldState == states.NewState)
            {
                return;
            }

            try
            {
                Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason);

                // Don't block on IO. This never faults.
                _ = _http2Output.WriteRstStreamAsync(error);

                AbortCore(abortReason);
            }
            finally
            {
                TryFireOnStreamCompleted(states);
            }
        }
Esempio n. 6
0
        private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error)
        {
            // Future incoming frames will drain for a default grace period to avoid destabilizing the connection.
            var states = ApplyCompletionFlag(StreamCompletionFlags.Aborted);

            if (states.OldState == states.NewState)
            {
                return;
            }

            try
            {
                Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason);

                // Don't block on IO. This never faults.
                _ = _http2Output.WriteRstStreamAsync(error);

                AbortCore(abortReason);
            }
            finally
            {
                TryFireOnStreamCompleted(states);
            }
        }