Skip to content

Commit

Permalink
FIXUP: Move the container existence check at the very end of the term…
Browse files Browse the repository at this point in the history
…ination phase
  • Loading branch information
apyrgio committed May 9, 2024
1 parent 7586cd5 commit 31e5275
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions dangerzone/isolation_provider/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,6 @@ def kill_container(self, name: str) -> None:
f"Unexpected error occurred while killing container '{name}': {str(e)}"
)

# Sanity check to see if the container has indeed exited. It has a unique ID, so
# it's safe to check for it's name in the command's output.
all_containers = subprocess.run(
[container_runtime, "ps", "-a"],
capture_output=True,
startupinfo=get_subprocess_startupinfo(),
)
if name in all_containers.stdout.decode():
log.warning(f"Container '{name}' did not stop gracefully")

def pixels_to_pdf(
self, document: Document, tempdir: str, ocr_lang: Optional[str]
) -> None:
Expand Down Expand Up @@ -319,6 +309,26 @@ def terminate_doc_to_pixels_proc(
self.kill_container(self.doc_to_pixels_container_name(document))
p.terminate()

def ensure_stop_doc_to_pixels_proc( # type: ignore [no-untyped-def]
self, document: Document, *args, **kwargs
) -> None:
super().ensure_stop_doc_to_pixels_proc(document, *args, **kwargs)

# Check if the container no longer exists, either because we successfully killed
# it, or because it exited on its own. We operate under the assumption that
# after a podman kill / docker kill invocation, this will likely be the case,
# else the container runtime (Docker/Podman) has experienced a problem, and we
# should report it.
container_runtime = self.get_runtime()
name = self.doc_to_pixels_container_name(document)
all_containers = subprocess.run(
[container_runtime, "ps", "-a"],
capture_output=True,
startupinfo=get_subprocess_startupinfo(),
)
if name in all_containers.stdout.decode():
log.warning(f"Container '{name}' did not stop gracefully")

def get_max_parallel_conversions(self) -> int:
# FIXME hardcoded 1 until length conversions are better handled
# https://github.com/freedomofpress/dangerzone/issues/257
Expand Down

0 comments on commit 31e5275

Please sign in to comment.