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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Fix asan warnings for req/res cycles.
Kishore Nallan9e9569c1cdef
diff --git a/include/http_server.h b/include/http_server.hindex 8edef305..b6465e43 100644--- a/include/http_server.h+++ b/include/http_server.h@@ -52,6 +52,9 @@ public:bool is_res_start = true;h2o_send_state_t send_state = H2O_SEND_STATE_IN_PROGRESS;h2o_iovec_t res_body{};+ h2o_iovec_t res_content_type{};+ int status = 0;+ const char* reason = nullptr;h2o_generator_t* generator = nullptr;@@ -65,10 +68,9 @@ public:res_body = h2o_strdup(&req->pool, body.c_str(), SIZE_MAX);if(is_res_start) {- req->res.status = status_code;- req->res.reason = http_res::get_status_reason(status_code);- h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE, NULL,- content_type.c_str(), content_type.size());+ res_content_type = h2o_strdup(&req->pool, content_type.c_str(), SIZE_MAX);+ status = status_code;+ reason = http_res::get_status_reason(status_code);}}diff --git a/src/core_api.cpp b/src/core_api.cppindex 8d367dfa..7de42f6a 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -58,10 +58,8 @@ void stream_response(const std::shared_ptr<http_req>& req, const std::shared_ptrreturn ;}- if(req->_req->res.status != 0) {- // not the first response chunk, so wait for previous chunk to finish- res->wait();- }+ // wait for previous chunk to finish (if any)+ res->wait();auto req_res = new async_req_res_t(req, res, true);server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, req_res);diff --git a/src/http_server.cpp b/src/http_server.cppindex b71a8a24..6a704153 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -632,6 +632,9 @@ int HttpServer::async_req_cb(void *ctx, int is_end_stream) {if(request->first_chunk_aggregate) {request->first_chunk_aggregate = false;++ // ensures that the first response need not wait for previous chunk to be done sending+ response->notify();}// default value for last_chunk_aggregate is false@@ -803,6 +806,13 @@ void HttpServer::stream_response(stream_response_state_t& state) {h2o_req_t* req = state.get_req();+ if(state.is_res_start) {+ h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE, NULL,+ state.res_content_type.base, state.res_content_type.len);+ req->res.status = state.status;+ req->res.reason = state.reason;+ }+if(state.is_req_early_exit) {// premature termination of async request: handle this explicitly as otherwise, request is not being closedLOG(INFO) << "Premature termination of async request.";