g_lock: Heuristically check for server existence
authorVolker Lendecke <vl@samba.org>
Mon, 22 May 2017 15:05:57 +0000 (17:05 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 15 Jun 2017 11:19:14 +0000 (13:19 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/g_lock.c

index 9f3d6cc8b5e48ee174f4127a36af4debc7dc7d1a..9342302382207de8b18d3c23fb8e2e3422c7d50c 100644 (file)
@@ -272,6 +272,22 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self,
 
        my_lock = num_locks;    /* doesn't exist yet */
 
+       if ((type == G_LOCK_READ) && (num_locks > 0)) {
+               /*
+                * Read locks can stay around forever if the process
+                * dies. Do a heuristic check for process existence:
+                * Check one random process for existence. Hopefully
+                * this will keep runaway read locks under control.
+                */
+               i = generate_random() % num_locks;
+
+               if (!serverid_exists(&locks[i].pid)) {
+                       locks[i] = locks[num_locks-1];
+                       num_locks -=1;
+                       modified = true;
+               }
+       }
+
        for (i=0; i<num_locks; i++) {
                struct g_lock_rec *lock = &locks[i];