[rpc] Raise a single exception on sessions leak check failure.
@@ -333,6 +333,7 @@ class ManagedConnection(Connection):
env=env,
cwd=local_service_binary.parent,
)
+ self._process_returncode_exception_raised = False
# Read the port from a file generated by the service.
wait_secs = 0.1
@@ -435,11 +436,16 @@ class ManagedConnection(Connection):
try:
self.process.terminate()
self.process.communicate(timeout=self.process_exit_max_seconds)
- if self.process.returncode:
- self.logger.fatal(
+ if (
+ self.process.returncode
+ and not self._process_returncode_exception_raised
+ ):
+ # You can call close() multiple times but we only want to emit
+ # the exception once.
+ self._process_returncode_exception_raised = True
+ raise ServiceError(
f"Service exited with returncode {self.process.returncode}"
)
- sys.exit(1)
except ProcessLookupError:
self.logger.warning("Service process not found at %s", self.working_dir)
except subprocess.TimeoutExpired:
