diff --git a/src/python/pants/bin/daemon_pants_runner.py b/src/python/pants/bin/daemon_pants_runner.py index 02055340ff7..ff0da1ed964 100644 --- a/src/python/pants/bin/daemon_pants_runner.py +++ b/src/python/pants/bin/daemon_pants_runner.py @@ -231,18 +231,16 @@ def nailgunned_stdio(cls, sock, env, handle_stdin=True): ) as finalizer: yield finalizer + # TODO: there's no testing for this method, and this caused a user-visible failure -- see #7008! def _raise_deferred_exc(self): """Raises deferred exceptions from the daemon's synchronous path in the post-fork client.""" if self._deferred_exception: - exc_type, exc_value, exc_traceback = self._deferred_exception - if exc_type == GracefulTerminationException: - self._exiter.exit(exc_value.exit_code) try: - # Expect `_deferred_exception` to be a 3-item tuple of the values returned by sys.exc_info(). - # This permits use the 3-arg form of the `raise` statement to preserve the original traceback. - raise_with_traceback(exc_type(exc_value), exc_traceback) - except ValueError: - # If `_deferred_exception` isn't a 3-item tuple, treat it like a bare exception. + exc_type, exc_value, exc_traceback = self._deferred_exception + raise_with_traceback(exc_value, exc_traceback) + except TypeError: + # If `_deferred_exception` isn't a 3-item tuple (raising a TypeError on the above + # destructuring), treat it like a bare exception. raise self._deferred_exception def _maybe_get_client_start_time_from_env(self, env): @@ -327,6 +325,10 @@ def post_fork_child(self): runner.run() except KeyboardInterrupt: self._exiter.exit_and_fail('Interrupted by user.\n') + except GracefulTerminationException as e: + ExceptionSink.log_exception( + 'Encountered graceful termination exception {}; exiting'.format(e)) + self._exiter.exit(e.exit_code) except Exception: ExceptionSink._log_unhandled_exception_and_exit() else: