mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 21:22:25 +08:00
Fix asan warnings for req/res cycles.
This commit is contained in:
parent
80641096c9
commit
9e9569c1cd
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,8 @@ void stream_response(const std::shared_ptr<http_req>& req, const std::shared_ptr
|
||||
return ;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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 closed
|
||||
LOG(INFO) << "Premature termination of async request.";
|
||||
|
Loading…
x
Reference in New Issue
Block a user