Skip to content

Commit 898de37

Browse files
simo5frozencemetery
authored andcommitted
Do not call gpm_grab_sock() twice
In the gpm_get_ctx() call, we unnecessarily call gpm_grab_sock() which would cause the lock to be held by one thread and never released. We already call gpm_grab_sock() as the first thing after gpm_get_ctx() in gpm_make_call(), plus gpm_make_call() properly releases the socket once done. This corrects the deadlock fix in 461a5fa, which incorrectly released the lock we wanted to grab. This caused the socket to not be locked to our thread. Another thread could come along and change the global ctx while we were still using the socket from another thread, causing concurrency issues as only one request can be in flight on any given socket at the same time. In special cases where the "thread" uid/gid changes (like in rpc.gssd), we end up closing the socket while we are still waiting for an answer from the server, causing additional issues and confusion. [[email protected]: squashed 2 commits; minor edits accordingly] Signed-off-by: Simo Sorce <[email protected]> Reviewed-by: Robbie Harwood <[email protected]> Merges: #218 Signed-off-by: Robbie Harwood <[email protected]>
1 parent ccbbd44 commit 898de37

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/client/gpm_common.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ static int gpm_grab_sock(struct gpm_ctx *gpmctx)
163163
ret = gpm_open_socket(gpmctx);
164164
}
165165

166-
pthread_mutex_unlock(&gpmctx->lock);
166+
if (ret) {
167+
pthread_mutex_unlock(&gpmctx->lock);
168+
}
167169
return ret;
168170
}
169171

@@ -518,11 +520,6 @@ static struct gpm_ctx *gpm_get_ctx(void)
518520

519521
pthread_once(&gpm_init_once_control, gpm_init_once);
520522

521-
ret = gpm_grab_sock(&gpm_global_ctx);
522-
if (ret) {
523-
return NULL;
524-
}
525-
526523
return &gpm_global_ctx;
527524
}
528525

0 commit comments

Comments
 (0)