Fix possible Logical error: Cannot write to finalized buffer

This commit is contained in:
avogar 2021-11-24 18:30:33 +03:00
parent 2da5c6b71b
commit 7c84d95908
3 changed files with 24 additions and 7 deletions

View File

@ -129,6 +129,8 @@ public:
} }
} }
bool isFinalized() const { return finalized; }
protected: protected:
virtual void finalizeImpl() virtual void finalizeImpl()
{ {

View File

@ -929,15 +929,25 @@ void HTTPHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
request_credentials.reset(); // ...so that the next requests on the connection have to always start afresh in case of exceptions. request_credentials.reset(); // ...so that the next requests on the connection have to always start afresh in case of exceptions.
}); });
tryLogCurrentException(log); /// Check if exception was thrown in used_output.finalize().
/// In this case used_output can be in invalid state and we
/// cannot write in it anymore. So, just log this exception.
if (used_output.isFinalized())
{
tryLogCurrentException(log, "Cannot flush data to client");
}
else
{
tryLogCurrentException(log);
/** If exception is received from remote server, then stack trace is embedded in message. /** If exception is received from remote server, then stack trace is embedded in message.
* If exception is thrown on local server, then stack trace is in separate field. * If exception is thrown on local server, then stack trace is in separate field.
*/ */
std::string exception_message = getCurrentExceptionMessage(with_stacktrace, true); std::string exception_message = getCurrentExceptionMessage(with_stacktrace, true);
int exception_code = getCurrentExceptionCode(); int exception_code = getCurrentExceptionCode();
trySendExceptionToClient(exception_message, exception_code, request, response, used_output); trySendExceptionToClient(exception_message, exception_code, request, response, used_output);
}
} }
used_output.finalize(); used_output.finalize();

View File

@ -74,6 +74,11 @@ private:
if (out) if (out)
out->finalize(); out->finalize();
} }
inline bool isFinalized() const
{
return out_maybe_delayed_and_compressed->isFinalized();
}
}; };
IServer & server; IServer & server;