From 55cf5ff3da9f3afc3cc0f995155b153e337be17c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 8 May 2022 17:52:19 +0900 Subject: [PATCH] nghttpd: Fix TLS read stall --- src/HttpServer.cc | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 6598e6f0..12149c67 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -749,37 +749,37 @@ int Http2Handler::read_tls() { ERR_clear_error(); - auto rv = SSL_read(ssl_, buf.data(), buf.size()); + for (;;) { + auto rv = SSL_read(ssl_, buf.data(), buf.size()); - if (rv <= 0) { - auto err = SSL_get_error(ssl_, rv); - switch (err) { - case SSL_ERROR_WANT_READ: - return write_(*this); - case SSL_ERROR_WANT_WRITE: - // renegotiation started - return -1; - default: + if (rv <= 0) { + auto err = SSL_get_error(ssl_, rv); + switch (err) { + case SSL_ERROR_WANT_READ: + return write_(*this); + case SSL_ERROR_WANT_WRITE: + // renegotiation started + return -1; + default: + return -1; + } + } + + auto nread = rv; + + if (get_config()->hexdump) { + util::hexdump(stdout, buf.data(), nread); + } + + rv = nghttp2_session_mem_recv(session_, buf.data(), nread); + if (rv < 0) { + if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { + std::cerr << "nghttp2_session_mem_recv() returned error: " + << nghttp2_strerror(rv) << std::endl; + } return -1; } } - - auto nread = rv; - - if (get_config()->hexdump) { - util::hexdump(stdout, buf.data(), nread); - } - - rv = nghttp2_session_mem_recv(session_, buf.data(), nread); - if (rv < 0) { - if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - std::cerr << "nghttp2_session_mem_recv() returned error: " - << nghttp2_strerror(rv) << std::endl; - } - return -1; - } - - return write_(*this); } int Http2Handler::write_tls() {