Browse Source

[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.
Dmitrii Kuvaiskii 5 years ago
parent
commit
5dd10ea66e
1 changed files with 7 additions and 7 deletions
  1. 7 7
      LibOS/shim/src/ipc/shim_ipc_nsimpl.h

+ 7 - 7
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;