From bcb1a39ef37a4b2d3b0e0837781a7f7dccd0823e Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 25 Aug 2009 17:52:31 +0200
Subject: [PATCH] ganeti-noded: Close listening socket in child

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/http/server.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/http/server.py b/lib/http/server.py
index b3e5b787a..d7e374c25 100644
--- a/lib/http/server.py
+++ b/lib/http/server.py
@@ -522,6 +522,16 @@ class HttpServer(http.HttpBase, asyncore.dispatcher):
     if pid == 0:
       # Child process
       try:
+        # The client shouldn't keep the listening socket open. If the parent
+        # process is restarted, it would fail when there's already something
+        # listening (in this case its own child from a previous run) on the
+        # same port.
+        try:
+          self.socket.close()
+        except socket.error:
+          pass
+        self.socket = None
+
         self.request_executor(self, connection, client_addr)
       except Exception:
         logging.exception("Error while handling request from %s:%s",
-- 
GitLab