From ee3ed42713690e3a50098dbc3970909ef888fb60 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Fri, 10 Mar 2023 17:07:05 +0530 Subject: [PATCH] Handle premature termination of resource-limited request. --- src/batched_indexer.cpp | 11 ++++++++--- src/raft_server.cpp | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/batched_indexer.cpp b/src/batched_indexer.cpp index 97d1088d..ea23388a 100644 --- a/src/batched_indexer.cpp +++ b/src/batched_indexer.cpp @@ -205,17 +205,19 @@ void BatchedIndexer::run() { std::string(magic_enum::enum_name(resource_check)); LOG(ERROR) << err_msg; orig_res->set_422(err_msg); + orig_res->final = true; async_req_res_t* async_req_res = new async_req_res_t(orig_req, orig_res, true); server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res); - break; + goto end; } else if(route_found) { if(skip_writes && found_rpath->handler != post_config) { orig_res->set(422, "Skipping write."); + orig_res->final = true; async_req_res_t* async_req_res = new async_req_res_t(orig_req, orig_res, true); server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res); - break; + goto end; } async_res = found_rpath->async_res; @@ -226,6 +228,7 @@ void BatchedIndexer::run() { LOG(ERROR) << "Raw error: " << e.what(); // bad request gets a response immediately orig_res->set_400("Bad request."); + orig_res->final = true; async_res = false; } prev_body = orig_req->body; @@ -240,10 +243,12 @@ void BatchedIndexer::run() { } if(!route_found) { - break; + goto end; } } + end: + queued_writes--; orig_req_res.next_chunk_index++; iter->Next(); diff --git a/src/raft_server.cpp b/src/raft_server.cpp index df0de966..1a1a45a5 100644 --- a/src/raft_server.cpp +++ b/src/raft_server.cpp @@ -202,6 +202,7 @@ void ReplicationState::write(const std::shared_ptr& request, const std if(config->get_skip_writes() && request->path_without_query != "/config") { response->set_422("Skipping writes."); + response->final = true; auto req_res = new async_req_res_t(request, response, true); return message_dispatcher->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, req_res); }