bug 1457996: fix issues preventing us from upgrading signing servers to newer gevent. r=catlee
authorBen Hearsum <bhearsum@mozilla.com>
Thu, 10 May 2018 09:22:45 -0400
changeset 8671 1380e34e96b928394d23bfaae9444aeb1f781053
parent 8670 8a6d5a340f963e9a113d2b220d559149a9597c32
child 8672 e69021feb46852b77108d216ee70b09600b1b0d5
push id285
push userbmo:jlorenzo@mozilla.com
push dateWed, 16 May 2018 11:50:30 +0000
reviewerscatlee
bugs1457996
bug 1457996: fix issues preventing us from upgrading signing servers to newer gevent. r=catlee
lib/python/signing/server.py
release/signing/signing-server.py
--- a/lib/python/signing/server.py
+++ b/lib/python/signing/server.py
@@ -509,17 +509,17 @@ class SigningServer:
             filename = self.get_filename(filehash)
             if filename:
                 log.debug("Looking for %s (%s)", fn, filename)
             else:
                 log.debug("Looking for %s", fn)
             checksum = sha1sum(fn)
             headers = [
                 ('X-SHA1-Digest', checksum),
-                ('Content-Length', os.path.getsize(fn)),
+                ('Content-Length', str(os.path.getsize(fn))),
             ]
             fp = open(fn, 'rb')
             os.utime(fn, None)
             log.debug("%s is OK", fn)
             start_response("200 OK", headers)
             while True:
                 data = fp.read(1024 ** 2)
                 if not data:
@@ -554,16 +554,20 @@ class SigningServer:
                         headers.append(('X-Pending', 'True'))
                     else:
                         log.debug("I don't remember the filename; re-submit please!")
             else:
                 self.misses += 1
 
             start_response("404 Not Found", headers)
             yield ""
+        except:
+            log.exception("ISE")
+            start_response("500 Internal Server Error", headers)
+            yield ""
 
     def handle_upload(self, environ, start_response, values, rest, next_nonce):
         format_ = rest[0]
         assert format_ in self.formats
         filehash = values['sha1']
         filename = values['filename']
         log.info("Request to %s sign %s (%s) from %s", format_,
                  filename, filehash, environ['REMOTE_ADDR'])
--- a/release/signing/signing-server.py
+++ b/release/signing/signing-server.py
@@ -282,16 +282,23 @@ if __name__ == '__main__':
         except OSError:
             # Process is done
             log.debug("pid %i has exited", pid)
 
     if options.daemonize:
         curdir = os.path.abspath(os.curdir)
         pidfile = os.path.abspath(options.pidfile)
         logfile = os.path.abspath(options.logfile)
+        # Clear out loggers before daemonize to avoid having duplicates
+        # after setting up logging again. For some reason the loggers
+        # don't work after daemonizing unless we set them up again,
+        # but if we don't clear them out *before* daemonizing we end up
+        # with two handlers, leading to duplicate log messages.
+        logger = logging.getLogger()
+        logger.handlers = []
 
         daemon_ctx = daemon.DaemonContext(
             # We do our own signal handling in run()
             signal_map={},
             working_directory=curdir,
             umask=0o077,
         )
         daemon_ctx.open()