BIND 10 trac1429, updated. 6583a47dde1b851aee99de3c38c6331a22ede260 [1429] Catch an exception

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Dec 6 10:07:42 UTC 2011


The branch, trac1429 has been updated
       via  6583a47dde1b851aee99de3c38c6331a22ede260 (commit)
       via  99033305fa90310135d37118a0d47df3f2223770 (commit)
       via  b7bbe25fdf0d0c168c24c904c82c7e04fc269bba (commit)
      from  9f792ee32ba42a44291277d0577196e03a929738 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6583a47dde1b851aee99de3c38c6331a22ede260
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Dec 6 11:07:28 2011 +0100

    [1429] Catch an exception

commit 99033305fa90310135d37118a0d47df3f2223770
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Dec 6 10:44:32 2011 +0100

    [1429] Constants instead of magic strings

commit b7bbe25fdf0d0c168c24c904c82c7e04fc269bba
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Dec 6 10:33:04 2011 +0100

    [1429] Logging

-----------------------------------------------------------------------

Summary of changes:
 src/bin/bind10/bind10_messages.mes     |   11 +++++++++++
 src/bin/bind10/bind10_src.py.in        |   21 ++++++++++++++++-----
 src/bin/bind10/tests/bind10_test.py.in |   15 +++++++++++++++
 3 files changed, 42 insertions(+), 5 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_messages.mes b/src/bin/bind10/bind10_messages.mes
index d850e47..82c1b99 100644
--- a/src/bin/bind10/bind10_messages.mes
+++ b/src/bin/bind10/bind10_messages.mes
@@ -99,6 +99,12 @@ The boss module is sending a kill signal to process with the given name,
 as part of the process of killing all started processes during a failed
 startup, as described for BIND10_KILLING_ALL_PROCESSES
 
+% BIND10_LOST_SOCKET_CONSUMER consumer of sockets disconnected, considering all its sockets closed
+A connection from one of the applications which requested a socket was
+closed. This means the application has terminated, so all the sockets it was
+using are now closed and bind10 process can release them as well, unless the
+same sockets are used by yet another application.
+
 % BIND10_MSGQ_ALREADY_RUNNING msgq daemon already running, cannot start
 There already appears to be a message bus daemon running. Either an
 old process was not shut down correctly, and needs to be killed, or
@@ -110,6 +116,11 @@ While listening on the message bus channel for messages, it suddenly
 disappeared. The msgq daemon may have died. This might lead to an
 inconsistent state of the system, and BIND 10 will now shut down.
 
+% BIND10_NO_SOCKET couldn't send a socket for token %1 because of error: %2
+An error occurred when the bind10 process was asked to send a socket file
+descriptor. The error is mentioned, most common reason is that the request
+is invalid and may not come from bind10 process at all.
+
 % BIND10_PROCESS_ENDED process %2 of %1 ended with status %3
 This indicates a process started previously terminated. The process id
 and component owning the process are indicated, as well as the exit code.
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index bf10090..da0514c 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -83,6 +83,10 @@ logger = isc.log.Logger("boss")
 DBG_PROCESS = logger.DBGLVL_TRACE_BASIC
 DBG_COMMANDS = logger.DBGLVL_TRACE_DETAIL
 
+# Messages sent over the unix domain socket to indicate if it is followed by a real socket
+CREATOR_SOCKET_OK = "1\n"
+CREATOR_SOCKET_UNAVAILABLE = "0\n"
+
 # Assign this process some longer name
 isc.util.process.rename(sys.argv[0])
 
@@ -869,11 +873,11 @@ class BoB:
         """
         try:
             fd = self._socket_cache.get_socket(token, unix_socket.fileno())
-            unix_socket.sendall("1\n")
+            unix_socket.sendall(CREATOR_SOCKET_OK)
             libutil_io_python.send_fd(unix_socket.fileno(), fd)
         except Exception as e:
-            # TODO Log
-            unix_socket.sendall("0\n")
+            logger.error(BIND10_NO_SOCKET, token, e)
+            unix_socket.sendall(CREATOR_SOCKET_UNAVAILABLE)
 
     def socket_consumer_dead(self, unix_socket):
         """
@@ -881,8 +885,15 @@ class BoB:
         sockets sent to it are to be considered closed. This function signals
         so to the _socket_cache.
         """
-        # TODO Log
-        self._socket_cache.drop_application(unix_socket.fileno())
+        logger.error(BIND10_LOST_SOCKET_CONSUMER, unix_socket.fileno())
+        try:
+            self._socket_cache.drop_application(unix_socket.fileno())
+        except ValueError:
+            # This means the application holds no sockets. It's harmless, as it
+            # can happen in real life - for example, it requests a socket, but
+            # get_socket doesn't find it, so the application dies. It should be
+            # rare, though.
+            pass
 
     def insert_creator(self, creator):
         """
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index e77ca6d..8dd1921 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -159,7 +159,12 @@ class TestCacheCommands(unittest.TestCase):
         """
         Part of pretending to be the cache. Logs the parameter to
         self.__drop_app_called.
+
+        In the case self.__raise_exception is set, the exception there
+        is raised instead.
         """
+        if self.__raise_exception is not None:
+            raise self.__raise_exception
         self.__drop_app_called = application
 
     def test_consumer_dead(self):
@@ -169,6 +174,16 @@ class TestCacheCommands(unittest.TestCase):
         self.__boss.socket_consumer_dead(self.FalseSocket())
         self.assertEqual(42, self.__drop_app_called)
 
+    def test_consumer_dead_invalid(self):
+        """
+        Test that it doesn't crash in case the application is not known to
+        the cache, the boss doesn't crash, as this actually can happen in
+        practice.
+        """
+        self.__raise_exception = ValueError("This application is unknown")
+        # This doesn't crash
+        self.__boss.socket_consumer_dead(self.FalseSocket())
+
     def get_socket(self, token, application):
         """
         Part of pretending to be the cache. If there's anything in




More information about the bind10-changes mailing list