You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ic...@apache.org on 2015/10/26 16:10:22 UTC

svn commit: r1710616 - in /httpd/httpd/trunk/modules/http2: h2_io.c h2_mplx.c h2_session.c h2_session.h h2_stream.h h2_version.h

Author: icing
Date: Mon Oct 26 15:10:22 2015
New Revision: 1710616

URL: http://svn.apache.org/viewvc?rev=1710616&view=rev
Log:
improvements in stream reset handling and early stream close

Modified:
    httpd/httpd/trunk/modules/http2/h2_io.c
    httpd/httpd/trunk/modules/http2/h2_mplx.c
    httpd/httpd/trunk/modules/http2/h2_session.c
    httpd/httpd/trunk/modules/http2/h2_session.h
    httpd/httpd/trunk/modules/http2/h2_stream.h
    httpd/httpd/trunk/modules/http2/h2_version.h

Modified: httpd/httpd/trunk/modules/http2/h2_io.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_io.c?rev=1710616&r1=1710615&r2=1710616&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_io.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_io.c Mon Oct 26 15:10:22 2015
@@ -91,6 +91,10 @@ apr_status_t h2_io_in_read(h2_io *io, ap
     apr_bucket *last;
     apr_status_t status;
 
+    if (io->rst_error) {
+        return APR_ECONNABORTED;
+    }
+    
     if (!io->bbin || APR_BRIGADE_EMPTY(io->bbin)) {
         return io->eos_in? APR_EOF : APR_EAGAIN;
     }
@@ -113,6 +117,10 @@ apr_status_t h2_io_in_read(h2_io *io, ap
 
 apr_status_t h2_io_in_write(h2_io *io, apr_bucket_brigade *bb)
 {
+    if (io->rst_error) {
+        return APR_ECONNABORTED;
+    }
+    
     if (io->eos_in) {
         return APR_EOF;
     }
@@ -129,6 +137,10 @@ apr_status_t h2_io_in_write(h2_io *io, a
 
 apr_status_t h2_io_in_close(h2_io *io)
 {
+    if (io->rst_error) {
+        return APR_ECONNABORTED;
+    }
+    
     if (io->bbin) {
         APR_BRIGADE_INSERT_TAIL(io->bbin, 
                                 apr_bucket_eos_create(io->bbin->bucket_alloc));
@@ -143,6 +155,10 @@ apr_status_t h2_io_out_readx(h2_io *io,
 {
     apr_status_t status;
     
+    if (io->rst_error) {
+        return APR_ECONNABORTED;
+    }
+    
     if (io->eos_out) {
         *plen = 0;
         *peos = 1;
@@ -169,6 +185,10 @@ apr_status_t h2_io_out_write(h2_io *io,
     apr_status_t status;
     int start_allowed;
     
+    if (io->rst_error) {
+        return APR_ECONNABORTED;
+    }
+
     if (io->eos_out) {
         apr_off_t len;
         /* We have already delivered an EOS bucket to a reader, no
@@ -199,9 +219,6 @@ apr_status_t h2_io_out_write(h2_io *io,
      */
     start_allowed = *pfile_handles_allowed;
 
-    if (io->rst_error) {
-        return APR_ECONNABORTED;
-    }
     status = h2_util_move(io->bbout, bb, maxlen, pfile_handles_allowed, 
                           "h2_io_out_write");
     /* track # file buckets moved into our pool */
@@ -214,6 +231,9 @@ apr_status_t h2_io_out_write(h2_io *io,
 
 apr_status_t h2_io_out_close(h2_io *io)
 {
+    if (io->rst_error) {
+        return APR_ECONNABORTED;
+    }
     if (!io->eos_out && !h2_util_has_eos(io->bbout, 0)) {
         APR_BRIGADE_INSERT_TAIL(io->bbout, 
                                 apr_bucket_eos_create(io->bbout->bucket_alloc));

Modified: httpd/httpd/trunk/modules/http2/h2_mplx.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_mplx.c?rev=1710616&r1=1710615&r2=1710616&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_mplx.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_mplx.c Mon Oct 26 15:10:22 2015
@@ -29,6 +29,7 @@
 #include "h2_private.h"
 #include "h2_config.h"
 #include "h2_conn.h"
+#include "h2_h2.h"
 #include "h2_io.h"
 #include "h2_io_set.h"
 #include "h2_response.h"
@@ -288,18 +289,21 @@ apr_status_t h2_mplx_cleanup_stream(h2_m
     status = apr_thread_mutex_lock(m->lock);
     if (APR_SUCCESS == status) {
         h2_io *io = h2_io_set_get(m->stream_ios, stream->id);
-        if (!io || io->task_done) {
-            /* No more io or task already done -> cleanup immediately */
-            stream_destroy(m, stream, io);
-        }
-        else {
+        if (io) {
+            /* Remove io from ready set, we will never submit it */
+            h2_io_set_remove(m->ready_ios, io);
             if (stream->rst_error) {
                 /* Forward error code to fail any further attempt to
                  * write to io */
                 h2_io_rst(io, stream->rst_error);
             }
-            /* Remove io from ready set (if there), since we will never submit it */
-            h2_io_set_remove(m->ready_ios, io);
+        }
+        
+        if (!io || io->task_done) {
+            /* No more io or task already done -> cleanup immediately */
+            stream_destroy(m, stream, io);
+        }
+        else {
             /* Add stream to closed set for cleanup when task is done */
             h2_stream_set_add(m->closed, stream);
         }
@@ -515,18 +519,21 @@ h2_stream *h2_mplx_next_submit(h2_mplx *
                     h2_stream_set_response(stream, io->response, io->bbout);
                 }
                 
-                if (io->output_drained) {
-                    apr_thread_cond_signal(io->output_drained);
-                }
             }
             else {
-                ap_log_cerror(APLOG_MARK, APLOG_WARNING, 0, m->c, APLOGNO(02953) 
-                              "h2_mplx(%ld): stream for response %d not found",
-                              m->id, io->id);
                 /* We have the io ready, but the stream has gone away, maybe
                  * reset by the client. Should no longer happen since such
                  * streams should clear io's from the ready queue.
                  */
+                ap_log_cerror(APLOG_MARK, APLOG_INFO, 0, m->c, APLOGNO(02953) 
+                              "h2_mplx(%ld): stream for response %d closed, "
+                              "resetting io to close request processing",
+                              m->id, io->id);
+                h2_io_rst(io, H2_ERR_STREAM_CLOSED);
+            }
+            
+            if (io->output_drained) {
+                apr_thread_cond_signal(io->output_drained);
             }
         }
         apr_thread_mutex_unlock(m->lock);

Modified: httpd/httpd/trunk/modules/http2/h2_session.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_session.c?rev=1710616&r1=1710615&r2=1710616&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_session.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_session.c Mon Oct 26 15:10:22 2015
@@ -168,7 +168,7 @@ static int on_data_chunk_recv_cb(nghttp2
                   session->id, stream_id, (int)len);
     if (status != APR_SUCCESS) {
         rv = nghttp2_submit_rst_stream(ngh2, NGHTTP2_FLAG_NONE, stream_id,
-                                       NGHTTP2_INTERNAL_ERROR);
+                                       H2_STREAM_RST(stream, H2_ERR_INTERNAL_ERROR));
         if (nghttp2_is_fatal(rv)) {
             return NGHTTP2_ERR_CALLBACK_FAILURE;
         }
@@ -931,17 +931,18 @@ apr_status_t h2_session_write(h2_session
     }
     
     /* If we have responses ready, submit them now. */
-    while ((stream = h2_mplx_next_submit(session->mplx, 
-                                         session->streams)) != NULL) {
+    while (!session->aborted 
+           && (stream = h2_mplx_next_submit(session->mplx, session->streams)) != NULL) {
         status = h2_session_handle_response(session, stream);
         flush_output = 1;
     }
     
-    if (h2_session_resume_streams_with_data(session) > 0) {
+    if (!session->aborted && h2_session_resume_streams_with_data(session) > 0) {
         flush_output = 1;
     }
     
-    if (!flush_output && timeout > 0 && !h2_session_want_write(session)) {
+    if (!session->aborted && !flush_output 
+        && timeout > 0 && !h2_session_want_write(session)) {
         status = h2_mplx_out_trywait(session->mplx, timeout, session->iowait);
 
         if (status != APR_TIMEUP
@@ -1151,13 +1152,10 @@ apr_status_t h2_session_handle_response(
     if (stream->response && stream->response->ngheader) {
         rv = submit_response(session, stream->response);
     }
-    else if (stream->rst_error) {
-        rv = nghttp2_submit_rst_stream(session->ngh2, NGHTTP2_FLAG_NONE,
-                                       stream->id, stream->rst_error);
-    }
     else {
         rv = nghttp2_submit_rst_stream(session->ngh2, NGHTTP2_FLAG_NONE,
-                                       stream->id, NGHTTP2_PROTOCOL_ERROR);
+                                       stream->id, 
+                                       H2_STREAM_RST(stream, H2_ERR_PROTOCOL_ERROR));
     }
     
     if (nghttp2_is_fatal(rv)) {
@@ -1179,27 +1177,6 @@ int h2_session_is_done(h2_session *sessi
                 && !nghttp2_session_want_write(session->ngh2)));
 }
 
-static int log_stream(void *ctx, h2_stream *stream)
-{
-    h2_session *session = (h2_session *)ctx;
-    AP_DEBUG_ASSERT(session);
-    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
-                  "h2_stream(%ld-%d): in set, suspended=%d, aborted=%d, "
-                  "has_data=%d",
-                  session->id, stream->id, stream->suspended, stream->aborted,
-                  h2_mplx_out_has_data_for(session->mplx, stream->id));
-    return 1;
-}
-
-void h2_session_log_stats(h2_session *session)
-{
-    AP_DEBUG_ASSERT(session);
-    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
-                  "h2_session(%ld): %d open streams",
-                  session->id, (int)h2_stream_set_size(session->streams));
-    h2_stream_set_iter(session->streams, log_stream, session);
-}
-
 static int frame_print(const nghttp2_frame *frame, char *buffer, size_t maxlen)
 {
     char scratch[128];

Modified: httpd/httpd/trunk/modules/http2/h2_session.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_session.h?rev=1710616&r1=1710615&r2=1710616&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_session.h (original)
+++ httpd/httpd/trunk/modules/http2/h2_session.h Mon Oct 26 15:10:22 2015
@@ -158,6 +158,4 @@ apr_status_t h2_session_handle_response(
 /* Get the h2_stream for the given stream idenrtifier. */
 struct h2_stream *h2_session_get_stream(h2_session *session, int stream_id);
 
-void h2_session_log_stats(h2_session *session);
-
 #endif /* defined(__mod_h2__h2_session__) */

Modified: httpd/httpd/trunk/modules/http2/h2_stream.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_stream.h?rev=1710616&r1=1710615&r2=1710616&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_stream.h (original)
+++ httpd/httpd/trunk/modules/http2/h2_stream.h Mon Oct 26 15:10:22 2015
@@ -70,6 +70,8 @@ struct h2_stream {
 };
 
 
+#define H2_STREAM_RST(s, def)    (s->rst_error? s->rst_error : (def))
+
 h2_stream *h2_stream_create(int id, apr_pool_t *pool, struct h2_mplx *m);
 
 apr_status_t h2_stream_destroy(h2_stream *stream);

Modified: httpd/httpd/trunk/modules/http2/h2_version.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_version.h?rev=1710616&r1=1710615&r2=1710616&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_version.h (original)
+++ httpd/httpd/trunk/modules/http2/h2_version.h Mon Oct 26 15:10:22 2015
@@ -20,7 +20,7 @@
  * @macro
  * Version number of the h2 module as c string
  */
-#define MOD_HTTP2_VERSION "1.0.1-DEV"
+#define MOD_HTTP2_VERSION "1.0.2-DEV"
 
 /**
  * @macro
@@ -28,7 +28,7 @@
  * release. This is a 24 bit number with 8 bits for major number, 8 bits
  * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
  */
-#define MOD_HTTP2_VERSION_NUM 0x010001
+#define MOD_HTTP2_VERSION_NUM 0x010002
 
 
 #endif /* mod_h2_h2_version_h */