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
Check for connection status before responding.
Kishore Nallan8ec653c3e6ee
diff --git a/src/batched_indexer.cpp b/src/batched_indexer.cppindex 2fdb760c..e149487e 100644--- a/src/batched_indexer.cpp+++ b/src/batched_indexer.cpp@@ -255,9 +255,11 @@ void BatchedIndexer::run() {const std::string& req_key_prefix = get_req_prefix_key(it->second.start_ts);store->delete_range(req_key_prefix, req_key_prefix + StringUtils::serialize_uint32_t(UINT32_MAX));- it->second.res->final = true;- async_req_res_t* async_req_res = new async_req_res_t(it->second.req, it->second.res, true);- server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res);+ if(it->second.res->is_alive) {+ it->second.res->final = true;+ async_req_res_t* async_req_res = new async_req_res_t(it->second.req, it->second.res, true);+ server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res);+ }it = req_res_map.erase(it);} else {diff --git a/src/core_api.cpp b/src/core_api.cppindex cdf67adf..ada733fc 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -34,9 +34,15 @@ bool handle_authentication(std::map<std::string, std::string>& req_params, constvoid stream_response(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {if(!res->is_alive) {+ // underlying request is dead or this is a raft log playbackreturn ;}+ if(req->_req->res.status != 0) {+ // not the first response chunk, so wait for previous chunk to finish+ 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 a62cd477..1a9d4a5d 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -767,6 +767,7 @@ void HttpServer::stream_response(stream_response_state_t& state) {if(state.res_body.len == 0 && state.send_state != H2O_SEND_STATE_FINAL) {// without this guard, http streaming will break+ state.generator->proceed(state.generator, req);return;}@@ -908,13 +909,15 @@ bool HttpServer::on_request_proceed_message(void *data) {// This callback will run concurrently to batch indexer's run() so care must be taken to protect access// to variables that are written to by the batch indexer, which for now is only: last_chunk_aggregate (atomic)deferred_req_res_t* req_res = static_cast<deferred_req_res_t *>(data);- auto stream_state = (req_res->req->last_chunk_aggregate) ? H2O_SEND_STATE_FINAL : H2O_SEND_STATE_IN_PROGRESS;+ if(req_res->res->is_alive) {+ auto stream_state = (req_res->req->last_chunk_aggregate) ? H2O_SEND_STATE_FINAL : H2O_SEND_STATE_IN_PROGRESS;- size_t written = req_res->req->chunk_len;- req_res->req->chunk_len = 0;+ size_t written = req_res->req->chunk_len;+ req_res->req->chunk_len = 0;- if(req_res->req->_req && req_res->req->_req->proceed_req) {- req_res->req->_req->proceed_req(req_res->req->_req, written, stream_state);+ if(req_res->req->_req && req_res->req->_req->proceed_req) {+ req_res->req->_req->proceed_req(req_res->req->_req, written, stream_state);+ }}if(req_res->destroy_after_use) {