From f096e4ff012cfb003ca3caba7c588e40204f0aa3 Mon Sep 17 00:00:00 2001
From: Benjamin Mahler <benjamin.mahler@gmail.com>
Date: Tue, 9 Dec 2014 19:14:07 -0800
Subject: [PATCH] *** Modified for 0.21.0-tw12 *** Fixed a regression within
 libprocess link management.

Review: https://reviews.apache.org/r/28887
---
 3rdparty/libprocess/src/process.cpp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index cbe3c34..ea2f57b 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -2433,7 +2433,9 @@ void SocketManager::exited(ProcessBase* process)
 
   synchronized (this) {
     // If this process had linked to anything, we need to clean
-    // up any pointers to it.
+    // up any pointers to it. Also, if this process was the last
+    // linker to a remote linkee, we must remove linkee from the
+    // remotes!
     if (links.linkees.contains(process)) {
       foreach (const UPID& linkee, links.linkees[process]) {
         CHECK(links.linkers.contains(linkee));
@@ -2441,6 +2443,18 @@ void SocketManager::exited(ProcessBase* process)
         links.linkers[linkee].erase(process);
         if (links.linkers[linkee].empty()) {
           links.linkers.erase(linkee);
+
+          // The exited process was the last linker for this linkee,
+          // so we need to remove the linkee from the remotes.
+          Node node(linkee.ip, linkee.port);
+          if (node.ip != __ip__ || node.port != __port__) {
+            CHECK(links.remotes.contains(node));
+
+            links.remotes[node].erase(linkee);
+            if (links.remotes[node].empty()) {
+              links.remotes.erase(node);
+            }
+          }
         }
       }
       links.linkees.erase(process);
-- 
2.0.4.218.g7ec489f-twtrsrc

