h2load: Fix crash when dealing connection: close with HTTP/1.1 server

This commit is contained in:
Tatsuhiro Tsujikawa 2015-11-26 21:26:00 +09:00
parent faad041868
commit 8e06e37375
2 changed files with 25 additions and 5 deletions

View File

@ -360,6 +360,16 @@ void Client::fail() {
if (new_connection_requested) {
new_connection_requested = false;
if (req_started < req_todo) {
// At the moment, we don't have a facility to re-start request
// already in in-flight. Make them fail.
auto req_abandoned = req_started - req_done;
worker->stats.req_failed += req_abandoned;
worker->stats.req_error += req_abandoned;
worker->stats.req_done += req_abandoned;
req_done = req_started;
// Keep using current address
if (connect() == 0) {
@ -367,6 +377,7 @@ void Client::fail() {
}
std::cerr << "client could not connect to host" << std::endl;
}
}
process_abandoned_streams();
}
@ -377,6 +388,7 @@ void Client::disconnect() {
ev_timer_stop(worker->loop, &request_timeout_watcher);
streams.clear();
session.reset();
wb.reset();
state = CLIENT_IDLE;
ev_io_stop(worker->loop, &wev);
ev_io_stop(worker->loop, &rev);

View File

@ -51,7 +51,15 @@ Http1Session::~Http1Session() {}
namespace {
// HTTP response message begin
int htp_msg_begincb(http_parser *htp) { return 0; }
int htp_msg_begincb(http_parser *htp) {
auto session = static_cast<Http1Session *>(htp->data);
if (session->stream_resp_counter_ >= session->stream_req_counter_) {
return -1;
}
return 0;
}
} // namespace
namespace {