Skip to content

Commit

Permalink
graceful stop worker when max_requests/realod_on_*
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Mar 8, 2024
1 parent 39f3ade commit 7686040
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 10 additions & 0 deletions core/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ void uwsgi_loop_cores_run(void *(*func) (void *)) {
}
long y = 0;
func((void *) y);

// main thread waits other threads.
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;

for (i = 1; i < uwsgi.threads; i++) {
int ret = pthread_join(uwsgi.workers[uwsgi.mywid].cores[i].thread_id, NULL);
if (ret) {
uwsgi_log("pthread_join() = %d\n", ret);
}
}
}

void uwsgi_setup_thread_req(long core_id, struct wsgi_request *wsgi_req) {
Expand Down
11 changes: 4 additions & 7 deletions core/uwsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,14 +1319,11 @@ void end_me(int signum) {
}

static void simple_goodbye_cruel_world(const char *reason) {

if (uwsgi.threads > 1 && !uwsgi_instance_is_dying) {
wait_for_threads();
}

int prev = uwsgi.workers[uwsgi.mywid].manage_next_request;
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;
uwsgi_log("...The work of process %d is done (%s). Seeya!\n", getpid(), (reason != NULL ? reason : "no reason given"));
exit(0);
if (prev) { // Avoid showing same message from all threads.
uwsgi_log("...The work of process %d is done (%s). Seeya!\n", getpid(), (reason != NULL ? reason : "no reason given"));
}
}

void goodbye_cruel_world(const char *reason_fmt, ...) {
Expand Down

0 comments on commit 7686040

Please sign in to comment.