From 508bec4238d87924e1a5a64a033ce8ab25d1163d Mon Sep 17 00:00:00 2001
From: Jim Jagielski <jim@apache.org>
Date: Wed, 10 Oct 2018 15:38:42 +0000
Subject: [PATCH] Merge r1843426 from trunk:

mod_http2: adding defensive code for stream EOS handling, in case the request handler
     missed to signal it the normal way (eos buckets). Addresses github issues
     https://github.com/icing/mod_h2/issues/164, https://github.com/icing/mod_h2/issues/167
     and https://github.com/icing/mod_h2/issues/170.


Submitted by: icing
Reviewed by: icing, ylavic, jim


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1843468 13f79535-47bb-0310-9956-ffa450edef68
---
 CHANGES                    | 5 +++++
 STATUS                     | 6 ------
 modules/http2/h2_session.c | 4 ++++
 modules/http2/h2_stream.c  | 2 +-
 modules/http2/h2_version.h | 4 ++--
 5 files changed, 12 insertions(+), 9 deletions(-)

# diff --git a/CHANGES b/CHANGES
# index 0b109fc6da..b145fee99e 100644
# --- a/CHANGES
# +++ b/CHANGES
# @@ -4,6 +4,11 @@ Changes with Apache 2.4.36
#    *) mod_proxy_scgi, mod_proxy_uwsgi: improve error handling when sending the
#       body of the response. [Jim Jagielski]
#  
# +  *) mod_http2: adding defensive code for stream EOS handling, in case the request handler
# +     missed to signal it the normal way (eos buckets). Addresses github issues 
# +     https://github.com/icing/mod_h2/issues/164, https://github.com/icing/mod_h2/issues/167
# +     and https://github.com/icing/mod_h2/issues/170. [Stefan Eissing] 
# +
#    *) ab: Add client certificate support. [Graham Leggett]
#  
#    *) ab: Disable printing temp key for OpenSSL before
# diff --git a/STATUS b/STATUS
# index 2e5aef65c7..e58751b0b8 100644
# --- a/STATUS
# +++ b/STATUS
# @@ -136,12 +136,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
#       in the 2.4.x patch.
#       +1: kotkov, ylavic, jim
#  
# -  *) mod_http2: fixing an issue that h2 stream do not properly EOS when
# -     the bucket is missing in the handler response.
# -     trunk patch: http://svn.apache.org/r1843426
# -     2.4.x patch: https://svn.apache.org/repos/asf/httpd/httpd/patches/2.4.x/h2-eos-fix.patch
# -     +1: icing, ylavic, jim
# -
#  
#  PATCHES PROPOSED TO BACKPORT FROM TRUNK:
#    [ New proposals should be added at the end of the list ]
diff --git a/modules/http2/h2_session.c b/modules/http2/h2_session.c
index a1b31d2b30..ed96cf06cd 100644
--- a/modules/http2/h2_session.c
+++ b/modules/http2/h2_session.c
@@ -1097,6 +1097,10 @@ static ssize_t stream_data_cb(nghttp2_session *ng2s,
         case APR_SUCCESS:
             break;
             
+        case APR_EOF:
+            eos = 1;
+            break;
+            
         case APR_ECONNRESET:
         case APR_ECONNABORTED:
             return NGHTTP2_ERR_CALLBACK_FAILURE;
diff --git a/modules/http2/h2_stream.c b/modules/http2/h2_stream.c
index 22c5902444..24ebc56023 100644
--- a/modules/http2/h2_stream.c
+++ b/modules/http2/h2_stream.c
@@ -919,7 +919,7 @@ apr_status_t h2_stream_out_prepare(h2_stream *stream, apr_off_t *plen,
                           (long)*plen, *peos);
         }
         else {
-            status = APR_EAGAIN;
+            status = (stream->output && h2_beam_is_closed(stream->output))? APR_EOF : APR_EAGAIN;
             ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
                           H2_STRM_MSG(stream, "prepare, no data"));
         }
diff --git a/modules/http2/h2_version.h b/modules/http2/h2_version.h
index 2ac718fc0f..13b7add273 100644
--- a/modules/http2/h2_version.h
+++ b/modules/http2/h2_version.h
@@ -27,7 +27,7 @@
  * @macro
  * Version number of the http2 module as c string
  */
-#define MOD_HTTP2_VERSION "1.11.0"
+#define MOD_HTTP2_VERSION "1.11.3"
 
 /**
  * @macro
@@ -35,7 +35,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 0x010b00
+#define MOD_HTTP2_VERSION_NUM 0x010b03
 
 
 #endif /* mod_h2_h2_version_h */
-- 
2.17.1

