diff --git a/src/controller/cluster.c b/src/controller/cluster.c index 9c9e48e..0e0b15c 100644 --- a/src/controller/cluster.c +++ b/src/controller/cluster.c @@ -557,8 +557,9 @@ static int make_heartbeat(cluster_t* c, endpoint_t* ep) static int check_worker_timeout_(void* arg1, void* arg2) { - cluster_t* c = (cluster_t*)arg1; - worker_t* w = (worker_t*)arg2; + cluster_t* c = (cluster_t*)arg1; + worker_t* w = (worker_t*)arg2; + worker_t* w1 = NULL; endpoint_t* ep; time_t now = time(NULL); int timeout; @@ -577,6 +578,12 @@ static int check_worker_timeout_(void* arg1, void* arg2) return 0; } + /* grab lock on worker */ + w1 = obj_ref(w, OBJREF_UPDATE); + if (w1 == NULL) { + return -EINVAL; + } + config = c->myconf->cluster_config; timeout = config->heartbeat_interval * config->inactive_heartbeat_count; @@ -585,6 +592,7 @@ static int check_worker_timeout_(void* arg1, void* arg2) w->host.name); mark_worker_unavail(c, w); + obj_deref(w1); return 0; } else { @@ -603,11 +611,14 @@ static int check_worker_timeout_(void* arg1, void* arg2) if (rc < 0) { ERROR("%s make_heartbeat to %s failed", __func__, w->host.name); + + obj_deref(w1); return rc; } } } + obj_deref(w1); return 0; } diff --git a/src/controller/worker.c b/src/controller/worker.c index 1e5e29f..0c21a2f 100644 --- a/src/controller/worker.c +++ b/src/controller/worker.c @@ -521,6 +521,8 @@ int handle_worker_leave(cluster_t* c, int idx) return -errno; } + w->ep = NULL; + mark_worker_unavail(c, w); obj_deref(w);