Welcome! Log In Create A New Profile

Advanced

patch: call modules' exit_process in reverse order

April 24, 2022 04:36AM
# HG changeset patch
# User stdanley <shanlei@asiainfo.com>
# Date 1650788278 -28800
# Sun Apr 24 16:17:58 2022 +0800
# Node ID 522acbe88486d027383075c8208edd6fcc0a3aa6
# Parent a736a7a613ea6e182ff86fbadcb98bb0f8891c0b
patch: call modules' exit_process in reverse order to solve module
dependency.
We once have developed a module which depends on ngx_thread_pool module.
but nginx hungs when began to shutdown. trace shows that ngx_thread_pool
cant finish "exit_process" because our module is using a thread, our
module must
call "exit_process" before ngx_thread_pool.
so we present this patch to solve modules' dependency issue.

diff -r a736a7a613ea -r 522acbe88486 src/os/unix/ngx_process_cycle.c
--- a/src/os/unix/ngx_process_cycle.c Tue Feb 08 17:35:27 2022 +0300
+++ b/src/os/unix/ngx_process_cycle.c Sun Apr 24 16:17:58 2022 +0800
@@ -300,10 +300,13 @@
ngx_process_events_and_timers(cycle);

if (ngx_terminate || ngx_quit) {
-
- for (i = 0; cycle->modules[i]; i++) {
- if (cycle->modules[i]->exit_process) {
- cycle->modules[i]->exit_process(cycle);
+ ngx_int_t j, k = 0;
+ //for (i = 0; cycle->modules[i]; i++) {
+ for (j = 0; cycle->modules[j]; j++, k++)
+ ;
+ for (j = k - 1; j >= 0; j--) {
+ if (cycle->modules[j]->exit_process) {
+ cycle->modules[j]->exit_process(cycle);
}
}

@@ -950,10 +953,14 @@
{
ngx_uint_t i;
ngx_connection_t *c;
+ ngx_int_t j, k=0;

- for (i = 0; cycle->modules[i]; i++) {
- if (cycle->modules[i]->exit_process) {
- cycle->modules[i]->exit_process(cycle);
+ //for (i = 0; cycle->modules[i]; i++) {
+ for (j = 0; cycle->modules[j]; j++, k++)
+ ;
+ for (j = k - 1; j >= 0; j--) {
+ if (cycle->modules[j]->exit_process) {
+ cycle->modules[j]->exit_process(cycle);
}
}

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

patch: call modules' exit_process in reverse order

shanlei 608 April 24, 2022 04:36AM

Re: patch: call modules' exit_process in reverse order

Maxim Dounin 169 April 27, 2022 07:58PM

Re: Re: patch: call modules' exit_process in reverse order

shanlei 193 April 29, 2022 01:26AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 171
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready