Skip to content

Commit

Permalink
[fix] Crash when receiving a custom admin request while exiting the p…
Browse files Browse the repository at this point in the history
…rocess
  • Loading branch information
pajama-coder committed Aug 21, 2023
1 parent c5c03c4 commit e6205dc
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/worker-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,24 @@ void WorkerThread::admin(pjs::Str *path, SharedData *request, const std::functio
request->retain();
m_net->post(
[=]() {
Data buf;
request->to_data(buf);
auto head = http::RequestHead::make();
head->path = pjs::Str::make(name);
pjs::Ref<Message> req = Message::make(head, Data::make(std::move(buf)));
if (!Worker::current()->admin(
req.get(),
[=](Message *response) {
auto body = response->body();
auto data = body ? SharedData::make(*body) : SharedData::make(Data());
data->retain();
Net::main().post([=]() { respond(data); data->release(); });
if (auto worker = Worker::current()) {
Data buf;
request->to_data(buf);
auto head = http::RequestHead::make();
head->path = pjs::Str::make(name);
pjs::Ref<Message> req = Message::make(head, Data::make(std::move(buf)));
if (!worker->admin(
req.get(),
[=](Message *response) {
auto body = response->body();
auto data = body ? SharedData::make(*body) : SharedData::make(Data());
data->retain();
Net::main().post([=]() { respond(data); data->release(); });
}
)) {
Net::main().post([=]() { respond(nullptr); });
}
)) {
} else {
Net::main().post([=]() { respond(nullptr); });
}
request->release();
Expand Down

0 comments on commit e6205dc

Please sign in to comment.