mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 06:40:30 +08:00
Fix premature close of async req on http/2
This commit is contained in:
parent
68e25fac09
commit
2d34bb66e6
@ -670,6 +670,27 @@ 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);
|
||||
|
||||
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
|
||||
LOG(INFO) << "Premature termination of async request.";
|
||||
|
||||
req->res.status = response->status_code;
|
||||
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()) {
|
||||
h2o_start_response(req, &custom_generator->super);
|
||||
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);
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
if (req->res.status == 0) {
|
||||
//LOG(INFO) << "h2o_start_response, content_type=" << response.content_type_header
|
||||
// << ",response.status_code=" << response.status_code;
|
||||
@ -691,13 +712,6 @@ void HttpServer::stream_response(const std::shared_ptr<http_req>& request, const
|
||||
const h2o_send_state_t state = custom_generator->res()->final ? H2O_SEND_STATE_FINAL : H2O_SEND_STATE_IN_PROGRESS;
|
||||
h2o_send(req, &body, 1, state);
|
||||
|
||||
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
|
||||
LOG(INFO) << "Premature termination of async request, disposing req object.";
|
||||
h2o_dispose_request(req);
|
||||
}
|
||||
|
||||
// LOG(INFO) << "stream_response after send";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user