Add shutdown detection

The maxscale_is_shutting_down function is used to detect when MaxScale
should stop. This fixes a race condition in the code where the workers has
not yet been initialized but a termination signal has been received. It
also replaces the misuse of the service_should_stop variable with a proper
function.
This commit is contained in:
Markus Mäkelä
2018-08-23 23:22:27 +03:00
parent 8f3eabb868
commit 8b653133a7
8 changed files with 43 additions and 19 deletions

View File

@ -34,6 +34,7 @@
#include <maxscale/alloc.h>
#include <maxscale/log.h>
#include <maxscale/maxscale.h>
#include <maxscale/pcre2.h>
#include <maxscale/utils.h>
@ -493,7 +494,7 @@ avro_binlog_end_t avro_read_all_events(Avro *router)
std::string next_binlog;
bool rotate_seen = false;
while (!service_should_stop)
while (!maxscale_is_shutting_down())
{
avro_binlog_end_t rc;
REP_HEADER hdr;

View File

@ -24,6 +24,7 @@
#include <ini.h>
#include <sys/stat.h>
#include <maxbase/atomic.h>
#include <maxscale/maxscale.h>
#include <maxbase/worker.hh>
#include <maxscale/alloc.h>
#include <maxscale/dcb.h>
@ -328,7 +329,7 @@ static bool conversion_task_ctl(Avro *inst, bool start)
{
bool rval = false;
if (!service_should_stop)
if (!maxscale_is_shutting_down())
{
Worker* worker = static_cast<Worker*>(mxs_rworker_get(MXS_RWORKER_MAIN));
std::unique_ptr<ConversionCtlTask> task(new (std::nothrow) ConversionCtlTask(inst, start));