aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2011-09-07 13:32:56 +0000
committerRob Austein <sra@hactrn.net>2011-09-07 13:32:56 +0000
commit37db542b72729b195d847aa7a4aa2e72fc255368 (patch)
tree4fb1ce43b97fddfcf4db9f620d583a3d165f3824
parent4d803d8217497625046ade2872ea2870f9eb55bc (diff)
Handle client close events and exceptions a bit more quietly and
aggressively in rpki-rtr server. svn path=/rtr-origin/rtr-origin.py; revision=3975
-rwxr-xr-xrtr-origin/rtr-origin.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/rtr-origin/rtr-origin.py b/rtr-origin/rtr-origin.py
index 6611929e..eb9dff38 100755
--- a/rtr-origin/rtr-origin.py
+++ b/rtr-origin/rtr-origin.py
@@ -29,6 +29,9 @@ import asyncore, asynchat, subprocess, traceback, getopt, bisect, random
# Debugging only, should be False in production
disable_incrementals = False
+# Whether to log backtraces
+backtrace_on_exceptions = False
+
class IgnoreThisRecord(Exception):
pass
@@ -1000,10 +1003,13 @@ class pdu_channel(asynchat.async_chat):
"""
Handle errors caught by asyncore main loop.
"""
- for line in traceback.format_exc().splitlines():
- log(line)
+ if backtrace_on_exceptions:
+ for line in traceback.format_exc().splitlines():
+ log(line)
+ else:
+ log("[Exception: %s]" % sys.exc_info()[1])
log("[Exiting after unhandled exception]")
- asyncore.close_all()
+ sys.exit(1)
def init_file_dispatcher(self, fd):
"""
@@ -1019,6 +1025,13 @@ class pdu_channel(asynchat.async_chat):
flags = flags | os.O_NONBLOCK
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
+ def handle_close(self):
+ """
+ Exit when channel closed.
+ """
+ asynchat.async_chat.handle_close(self)
+ sys.exit(0)
+
class server_write_channel(pdu_channel):
"""
Kludge to deal with ssh's habit of sometimes (compile time option)
@@ -1094,14 +1107,6 @@ class server_channel(pdu_channel):
"""
pdu.serve(self)
- def handle_close(self):
- """
- Intercept close event so we can shut down other sockets.
- """
- asynchat.async_chat.handle_close(self)
- asyncore.close_all()
- sys.exit(0)
-
def get_serial(self):
"""
Read, cache, and return current serial number, or None if we can't
@@ -1205,7 +1210,7 @@ class client_channel(pdu_channel):
Intercept close event so we can log it, then shut down.
"""
blather("Server closed channel")
- sys.exit(0)
+ pdu_channel.handle_close(self)
class kickme_channel(asyncore.dispatcher):
"""
@@ -1272,10 +1277,13 @@ class kickme_channel(asyncore.dispatcher):
"""
Handle errors caught by asyncore main loop.
"""
- for line in traceback.format_exc().splitlines():
- log(line)
+ if backtrace_on_exceptions:
+ for line in traceback.format_exc().splitlines():
+ log(line)
+ else:
+ log("[Exception: %s]" % sys.exc_info()[1])
log("[Exiting after unhandled exception]")
- asyncore.close_all()
+ sys.exit(1)
def hostport_tag():