Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Handle failures during import.

Kishore Nallan1b004d3865a9
diff --git a/src/http_server.cpp b/src/http_server.cpp
index 6e7f2252..f2b602ac 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -670,6 +670,8 @@ void HttpServer::stream_response(const std::shared_ptr<http_req>& request, const
h2o_req_t* req = request->_req;
h2o_custom_generator_t* custom_generator = reinterpret_cast<h2o_custom_generator_t *>(response->generator);
+ response->status_code = (response->status_code == 0) ? 503 : response->status_code; // just to be sure
+
if(custom_generator->rpath->async_req && custom_generator->res()->final &&
!custom_generator->req()->last_chunk_aggregate) {
// premature termination of async request: handle this explicitly as otherwise, request is not being closed
@@ -679,12 +681,14 @@ void HttpServer::stream_response(const std::shared_ptr<http_req>& request, const
req->res.reason = http_res::get_status_reason(response->status_code);
h2o_iovec_t body = h2o_strdup(&req->pool, response->body.c_str(), SIZE_MAX);
- if(request->is_http_v1()) {
+ if (req->_generator == nullptr) {
h2o_start_response(req, &custom_generator->super);
+ }
+
+ if(request->is_http_v1()) {
h2o_send(req, &body, 1, H2O_SEND_STATE_FINAL);
h2o_dispose_request(req);
} else {
- h2o_start_response(req, &custom_generator->super);
h2o_send(req, &body, 1, H2O_SEND_STATE_ERROR);
}
@@ -694,7 +698,6 @@ void HttpServer::stream_response(const std::shared_ptr<http_req>& request, const
if (req->res.status == 0) {
//LOG(INFO) << "h2o_start_response, content_type=" << response.content_type_header
// << ",response.status_code=" << response.status_code;
- response->status_code = (response->status_code == 0) ? 503 : response->status_code; // just to be sure
req->res.status = response->status_code;
req->res.reason = http_res::get_status_reason(response->status_code);
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE, NULL,
diff --git a/src/raft_server.cpp b/src/raft_server.cpp
index b851d18d..d6bff1b8 100644
--- a/src/raft_server.cpp
+++ b/src/raft_server.cpp
@@ -192,12 +192,12 @@ void ReplicationState::write_to_leader(const std::shared_ptr<http_req>& request,
h2o_custom_generator_t* custom_generator = reinterpret_cast<h2o_custom_generator_t *>(response->generator);
HttpServer* server = custom_generator->h2o_handler->http_server;
- thread_pool->enqueue([leader_addr, request, response, server, this]() {
- auto raw_req = request->_req;
- const std::string& path = std::string(raw_req->path.base, raw_req->path.len);
- const std::string& scheme = std::string(raw_req->scheme->name.base, raw_req->scheme->name.len);
- const std::string url = get_leader_url_path(leader_addr, path, scheme);
+ auto raw_req = request->_req;
+ const std::string& path = std::string(raw_req->path.base, raw_req->path.len);
+ const std::string& scheme = std::string(raw_req->scheme->name.base, raw_req->scheme->name.len);
+ const std::string url = get_leader_url_path(leader_addr, path, scheme);
+ thread_pool->enqueue([request, response, server, path, url, this]() {
pending_writes++;
std::map<std::string, std::string> res_headers;