Welcome! Log In Create A New Profile

Advanced

[PATCH 2 of 2] Unlock of shared memory zones on process crash

Maxim Dounin
November 17, 2011 08:30PM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1321579276 -10800
# Node ID e32c7ec2800b43ad5fe4bf98bc69fda4abdadf39
# Parent 98907592714e29982979010e310cd482d414b53f
Unlock of shared memory zones on process crash.

If process exited abnormally while holding lock on some shared memory zone -
unlock it. It may be not safe thing to do (as crash with lock held may
result in corrupted shared memory structure, and other processes will
subsequently crash while trying to access shared data), therefore complain
loudly if unlock succeeds.

diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -445,12 +445,15 @@ ngx_signal_handler(int signo)
static void
ngx_process_get_status(void)
{
- int status;
- char *process;
- ngx_pid_t pid;
- ngx_err_t err;
- ngx_int_t i;
- ngx_uint_t one;
+ int status;
+ char *process;
+ ngx_pid_t pid;
+ ngx_err_t err;
+ ngx_int_t i;
+ ngx_uint_t n, one;
+ ngx_shm_zone_t *shm_zone;
+ ngx_list_part_t *part;
+ ngx_slab_pool_t *sp;

one = 0;

@@ -497,17 +500,6 @@ ngx_process_get_status(void)
}


- if (ngx_accept_mutex_ptr) {
-
- /*
- * unlock the accept mutex if the abnormally exited process
- * held it
- */
-
- ngx_shmtx_force_unlock(&ngx_accept_mutex, pid);
- }
-
-
one = 1;
process = "unknown process";

@@ -545,6 +537,46 @@ ngx_process_get_status(void)
process, pid, WEXITSTATUS(status));
ngx_processes[i].respawn = 0;
}
+
+
+ if (ngx_accept_mutex_ptr) {
+
+ /*
+ * unlock the accept mutex if the abnormally exited process
+ * held it
+ */
+
+ ngx_shmtx_force_unlock(&ngx_accept_mutex, pid);
+ }
+
+
+ /*
+ * unlock shared memory mutexes if held by the abnormally exited
+ * process
+ */
+
+ part = (ngx_list_part_t *) &ngx_cycle->shared_memory.part;
+ shm_zone = part->elts;
+
+ for (n = 0; /* void */ ; n++) {
+
+ if (n >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+ part = part->next;
+ shm_zone = part->elts;
+ n = 0;
+ }
+
+ sp = (ngx_slab_pool_t *) shm_zone[n].shm.addr;
+
+ if (ngx_shmtx_force_unlock(&sp->mutex, pid)) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
+ "shared memory zone \"%V\" was locked by %P",
+ &shm_zone[n].shm.name, pid);
+ }
+ }
}
}


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 0 of 2] unlock mutexes on process crash

Maxim Dounin 1214 November 17, 2011 08:30PM

[PATCH 1 of 2] Added shmtx interface to forcibly unlock mutexes

Maxim Dounin 689 November 17, 2011 08:30PM

[PATCH 2 of 2] Unlock of shared memory zones on process crash

Maxim Dounin 498 November 17, 2011 08:30PM



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

Online Users

Guests: 162
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