From 5dd10ea66e206453de63451a3ca828aee96fb44a Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Mon, 8 Jul 2019 19:18:44 -0700 Subject: [PATCH] [LibOS] Force current process to become leader if failed to send FINDNS Previously, there was an incorrect corner case during discovering of the current namespace leader. If the parent process would exit before the child, the child process would fail on sending FINDNS message to the parent (because of closed parent socket). The previous code logic would assume that since NS_LEADER is set to some value, the leader process exists. In reality, the child loses the only source of information about the leader process (note that FINDNS is sent only to the parent), so the only meaningful action is to set myself as the new leader. --- LibOS/shim/src/ipc/shim_ipc_nsimpl.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/LibOS/shim/src/ipc/shim_ipc_nsimpl.h b/LibOS/shim/src/ipc/shim_ipc_nsimpl.h index 817ea5c0..90d2d2f1 100644 --- a/LibOS/shim/src/ipc/shim_ipc_nsimpl.h +++ b/LibOS/shim/src/ipc/shim_ipc_nsimpl.h @@ -795,7 +795,8 @@ static void __discover_ns (bool block, bool need_locate) // Send out an IPC message to find out the namespace information. // If the call is non-blocking, can't expect the answer when the function finishes. - if (!NS_SEND(findns)(block)) { + int ret = NS_SEND(findns)(block); + if (!ret) { ipc_pending = !block; // There is still some unfinished business with IPC lock(&cur_process.lock); assert(NS_LEADER); @@ -804,18 +805,17 @@ static void __discover_ns (bool block, bool need_locate) lock(&cur_process.lock); - if (NS_LEADER && (!need_locate || !qstrempty(&NS_LEADER->uri))) - goto out; + // At this point, (1) the leader is not me, (2) I don't know leader's URI, + // and (3) I failed to find out the leader via IPC. But I am pressed to + // report the leader so promote myself (and remove stale leader info). + if (NS_LEADER) + put_ipc_info(NS_LEADER); - // If all other ways failed, the current process becomes the leader if (!need_locate) { NS_LEADER = create_ipc_info(cur_process.vmid, NULL, 0); goto out; } - if (NS_LEADER) - put_ipc_info(NS_LEADER); - if (!(NS_LEADER = create_ipc_info_cur_process())) goto out;