From 2eaadcf4e7f4a3a9c246f32090d03fbb61209677 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 19 May 2020 20:16:36 +0200 Subject: Bugfix: Keep FCGI connections really open --- plugins/fcgi/fcgi.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/plugins/fcgi/fcgi.cpp b/plugins/fcgi/fcgi.cpp index a1529bc..5a7ce65 100644 --- a/plugins/fcgi/fcgi.cpp +++ b/plugins/fcgi/fcgi.cpp @@ -356,8 +356,6 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) std::lock_guard socket_lock{socket->getMutex()}; - socket->close(); // TODO: Bug workaround: Keeping socket open doesn't work for now. Subsequent requests are cancelled because connection is already closed by server. - if (!socket->is_open()) { //std::cout << "FCGI: Opening new socket" << std::endl; @@ -373,36 +371,35 @@ std::string fcgi_plugin::fcgiQuery(FCGIContext& context) uint16_t id {id_guard.getID()}; try { + std::vector buffer; + if (opening) { FCGI_Record get_values{FCGI_GET_VALUES, 0, system_config_bytes}; - if (socket->write(get_values.getBuffer()) != get_values.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 1" << std::endl; + buffer.insert(buffer.end(), get_values.getBuffer().begin(), get_values.getBuffer().end()); } FCGI_Record begin_request{FCGI_BEGIN_REQUEST, id, FCGI_RESPONDER, FCGI_KEEP_CONN}; - if (socket->write(begin_request.getBuffer()) != begin_request.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 2" << std::endl; + buffer.insert(buffer.end(), begin_request.getBuffer().begin(), begin_request.getBuffer().end()); FCGI_Record params{FCGI_PARAMS, id, env_bytes}; - if (socket->write(params.getBuffer()) != params.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 3" << std::endl; + buffer.insert(buffer.end(), params.getBuffer().begin(), params.getBuffer().end()); if (env_bytes.size()) { FCGI_Record params_end{FCGI_PARAMS, id, std::string{}}; - if (socket->write(params_end.getBuffer()) != params_end.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 4" << std::endl; + buffer.insert(buffer.end(), params_end.getBuffer().begin(), params_end.getBuffer().end()); } std::string body {context.GetRequestParam("body")}; FCGI_Record stdin_{FCGI_STDIN, id, body}; - if (socket->write(stdin_.getBuffer()) != stdin_.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 5" << std::endl; + buffer.insert(buffer.end(), stdin_.getBuffer().begin(), stdin_.getBuffer().end()); if (body.size()) { FCGI_Record stdin_end{FCGI_STDIN, id, std::string{}}; - if (socket->write(stdin_end.getBuffer()) != stdin_end.getBuffer().size()) - std::cerr << "Warning: Not all bytes written 6" << std::endl; + buffer.insert(buffer.end(), stdin_end.getBuffer().begin(), stdin_end.getBuffer().end()); } + + if (socket->write(buffer) != buffer.size()) + std::cerr << "Warning: Not all bytes written" << std::endl; } catch (const fcgi_eof_error&) { std::cerr << "FCGI Error: EOF on write" << std::endl; // seems to be ok here return HttpStatus("500", "FCGI connection: EOF on write", context.SetResponseHeader); -- cgit v1.2.3