From d19e7709d9b6666f53ccfec47a86f0f0cab70925 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 22 May 2017 17:05:57 +0200 Subject: [PATCH] g_lock: Heuristically check for server existence Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/lib/g_lock.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 9f3d6cc8b5e..93423023822 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -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