diff options
author | Rob Austein <sra@hactrn.net> | 2014-11-19 19:52:54 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2014-11-19 19:52:54 +0000 |
commit | 06f6dd3a2ff8ba58c8edfa9ed3d2b12b0b9a7ca4 (patch) | |
tree | 6c928941435ae0da88d7400156c5a969751d55ba | |
parent | f8316a5c3a72230782f4a1e7d941e627e49ebced (diff) |
Add disable_signal_handlers option to rpki.async.sync_wrapper and
rpki.irdb.Zookeeper() to avoid problems when running in environments
like mod_wsgi which have strong opinions about what code is and is not
allowed to handle signals. This may result in some noise in log
files, but there's not much we can do about that if we're not allowed
to clean up when terminated, so be it. See #681.
svn path=/trunk/; revision=6027
-rw-r--r-- | rpki/async.py | 8 | ||||
-rw-r--r-- | rpki/irdb/zookeeper.py | 39 |
2 files changed, 28 insertions, 19 deletions
diff --git a/rpki/async.py b/rpki/async.py index b17c31ed..75b4b656 100644 --- a/rpki/async.py +++ b/rpki/async.py @@ -339,8 +339,9 @@ class sync_wrapper(object): err = None fin = False - def __init__(self, func): + def __init__(self, func, disable_signal_handlers = False): self.func = func + self.disable_signal_handlers = disable_signal_handlers def cb(self, res = None): """ @@ -374,7 +375,10 @@ class sync_wrapper(object): self.eb(e) event_defer(thunk) - event_loop() + if self.disable_signal_handlers: + event_loop(catch_signals = ()) + else: + event_loop() if not self.fin: logger.warning("%r event_loop terminated without callback or errback", self) if self.err is None: diff --git a/rpki/irdb/zookeeper.py b/rpki/irdb/zookeeper.py index 1e163a4d..3fba99f9 100644 --- a/rpki/irdb/zookeeper.py +++ b/rpki/irdb/zookeeper.py @@ -193,7 +193,7 @@ class Zookeeper(object): show_xml = False - def __init__(self, cfg = None, handle = None, logstream = None): + def __init__(self, cfg = None, handle = None, logstream = None, disable_signal_handlers = False): if cfg is None: cfg = rpki.config.parser() @@ -204,6 +204,7 @@ class Zookeeper(object): self.cfg = cfg self.logstream = logstream + self.disable_signal_handlers = disable_signal_handlers self.run_rpkid = cfg.getboolean("run_rpkid", section = myrpki_section) self.run_pubd = cfg.getboolean("run_pubd", section = myrpki_section) @@ -1059,14 +1060,16 @@ class Zookeeper(object): elif len(pdus) == 1 and isinstance(pdus[0], (tuple, list)): pdus = pdus[0] - call_rpkid = rpki.async.sync_wrapper(rpki.http.caller( - proto = rpki.left_right, - client_key = irbe.private_key, - client_cert = irbe.certificate, - server_ta = self.server_ca.certificate, - server_cert = rpkid.certificate, - url = url, - debug = self.show_xml)) + call_rpkid = rpki.async.sync_wrapper( + disable_signal_handlers = self.disable_signal_handlers, + func = rpki.http.caller( + proto = rpki.left_right, + client_key = irbe.private_key, + client_cert = irbe.certificate, + server_ta = self.server_ca.certificate, + server_cert = rpkid.certificate, + url = url, + debug = self.show_xml)) return call_rpkid(*pdus) @@ -1169,14 +1172,16 @@ class Zookeeper(object): elif len(pdus) == 1 and isinstance(pdus[0], (tuple, list)): pdus = pdus[0] - call_pubd = rpki.async.sync_wrapper(rpki.http.caller( - proto = rpki.publication, - client_key = irbe.private_key, - client_cert = irbe.certificate, - server_ta = self.server_ca.certificate, - server_cert = pubd.certificate, - url = url, - debug = self.show_xml)) + call_pubd = rpki.async.sync_wrapper( + disable_signal_handlers = self.disable_signal_handlers, + func = rpki.http.caller( + proto = rpki.publication, + client_key = irbe.private_key, + client_cert = irbe.certificate, + server_ta = self.server_ca.certificate, + server_cert = pubd.certificate, + url = url, + debug = self.show_xml)) return call_pubd(*pdus) |