mirror of
https://github.com/typesense/typesense.git
synced 2025-05-17 04:02:36 +08:00
Handle response write race condition with h2o dispose.
This commit is contained in:
parent
805932c7d7
commit
4549e09063
@ -41,6 +41,8 @@ struct http_res {
|
||||
std::string body;
|
||||
std::atomic<bool> final;
|
||||
|
||||
std::shared_mutex mres;
|
||||
|
||||
std::atomic<bool> is_alive;
|
||||
std::atomic<void*> generator = nullptr;
|
||||
|
||||
|
@ -109,6 +109,8 @@ public:
|
||||
const bool destroy_after_use) :
|
||||
req(h_req), res(h_res), destroy_after_use(destroy_after_use), res_state(h_req->_req) {
|
||||
|
||||
std::shared_lock lk(res->mres);
|
||||
|
||||
if(!res->is_alive || req->_req == nullptr || res->generator == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -261,11 +261,15 @@ void HttpServer::on_res_generator_dispose(void *self) {
|
||||
//LOG(INFO) << "on_res_generator_dispose fires";
|
||||
h2o_custom_generator_t* custom_generator = *static_cast<h2o_custom_generator_t**>(self);
|
||||
|
||||
custom_generator->res()->final = true;
|
||||
custom_generator->res()->generator = nullptr;
|
||||
custom_generator->res()->is_alive = false;
|
||||
custom_generator->req()->notify();
|
||||
custom_generator->res()->notify();
|
||||
// locking to ensure dispose does not happen while the h2o req object is being written to
|
||||
{
|
||||
std::unique_lock lk(custom_generator->res()->mres);
|
||||
custom_generator->res()->final = true;
|
||||
custom_generator->res()->generator = nullptr;
|
||||
custom_generator->res()->is_alive = false;
|
||||
custom_generator->req()->notify();
|
||||
custom_generator->res()->notify();
|
||||
}
|
||||
|
||||
delete custom_generator;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user