Skip to content

Commit

Permalink
fix bug issue 1554: using unique_ptr.reset to fix the SIGABRT error (#…
Browse files Browse the repository at this point in the history
…1595)

using unique_ptr.reset to fix the SIGABRT error && using time-wait lock to notify quickly
  • Loading branch information
AlexStocks authored Jun 7, 2023
1 parent c128813 commit ca44785
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class PikaServer : public pstd::noncopyable {
void InitStorageOptions();

std::atomic<bool> exit_;
std::timed_mutex exit_mutex_;

/*
* Table used
Expand Down
16 changes: 12 additions & 4 deletions src/pika.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#include "include/pika_rm.h"
#include "include/pika_server.h"
#include "include/pika_version.h"

#include "pstd/include/env.h"
#include "pstd/include/pstd_defer.h"

std::unique_ptr<PikaConf> g_pika_conf;
// todo : change to unique_ptr will coredump
PikaServer* g_pika_server;
PikaServer* g_pika_server = nullptr;
std::unique_ptr<PikaReplicaManager> g_pika_rm;

std::unique_ptr<PikaCmdTableManager> g_pika_cmd_table_manager;
Expand Down Expand Up @@ -194,6 +196,15 @@ int main(int argc, char* argv[]) {
close_std();
}

DEFER {
delete g_pika_server;
g_pika_server = nullptr;
g_pika_rm.reset();
g_pika_cmd_table_manager.reset();
::google::ShutdownGoogleLogging();
g_pika_conf.reset();
};

g_pika_rm->Start();
g_pika_server->Start();

Expand All @@ -205,8 +216,5 @@ int main(int argc, char* argv[]) {
// may references to dead PikaServer
g_pika_rm->Stop();

delete g_pika_server;
::google::ShutdownGoogleLogging();

return 0;
}
13 changes: 8 additions & 5 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ PikaServer::PikaServer()
pika_auxiliary_thread_ = std::make_unique<PikaAuxiliaryThread>();

pika_client_processor_ = std::make_unique<PikaClientProcessor>(g_pika_conf->thread_pool_size(), 100000);
exit_mutex_.lock();
}

PikaServer::~PikaServer() {
Expand Down Expand Up @@ -177,16 +178,18 @@ void PikaServer::Start() {
LOG(INFO) << "Pika Server going to start";
while (!exit_) {
DoTimingTask();
// wake up every 10 second
int try_num = 0;
while (!exit_ && try_num++ < 5) {
sleep(1);
// wake up every 5 seconds
if (!exit_ && exit_mutex_.try_lock_for(std::chrono::seconds(5))) {
exit_mutex_.unlock();
}
}
LOG(INFO) << "Goodbye...";
}

void PikaServer::Exit() { exit_ = true; }
void PikaServer::Exit() {
exit_mutex_.unlock();
exit_ = true;
}

std::string PikaServer::host() { return host_; }

Expand Down

0 comments on commit ca44785

Please sign in to comment.