fix kill worker cause controller die

This commit is contained in:
Rongsong Shen 2026-01-23 18:21:12 +08:00
parent 9e07a1b227
commit 06c561cea4
2 changed files with 15 additions and 2 deletions

View file

@ -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;
}

View file

@ -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);