mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
isolation_provider: Get exit code without timing out
Get the exit code of the spawned process for the doc-to-pixels phase, without timing out. More specifically, if the spawned process has not finished within a generous amount of time (hardcode to 15 seconds), return UnexpectedConversionError, with a custom message. This way, the happy path is not affected, and we still make our best to learn the underlying cause of the I/O error.
This commit is contained in:
parent
171a7eca52
commit
cd4cbdb00a
1 changed files with 17 additions and 2 deletions
|
@ -22,6 +22,7 @@ DOC_TO_PIXELS_LOG_END = "----- DOC TO PIXELS LOG END -----"
|
|||
PIXELS_TO_PDF_LOG_START = "----- PIXELS TO PDF LOG START -----"
|
||||
PIXELS_TO_PDF_LOG_END = "----- PIXELS TO PDF LOG END -----"
|
||||
|
||||
TIMEOUT_EXCEPTION = 15
|
||||
|
||||
def read_bytes(f: IO[bytes], size: int, exact: bool = True) -> bytes:
|
||||
"""Read bytes from a file-like object."""
|
||||
|
@ -174,9 +175,23 @@ class IsolationProvider(ABC):
|
|||
if self.progress_callback:
|
||||
self.progress_callback(error, text, percentage)
|
||||
|
||||
def get_proc_exception(self, p: subprocess.Popen) -> Exception:
|
||||
def get_proc_exception(
|
||||
self, p: subprocess.Popen, timeout: int = TIMEOUT_EXCEPTION
|
||||
) -> Exception:
|
||||
"""Returns an exception associated with a process exit code"""
|
||||
error_code = p.wait(3)
|
||||
try:
|
||||
error_code = p.wait(timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
return errors.UnexpectedConversionError(
|
||||
"Encountered an I/O error during document to pixels conversion,"
|
||||
f" but the conversion process is still running after {timeout} seconds"
|
||||
f" (PID: {p.pid})"
|
||||
)
|
||||
except Exception:
|
||||
return errors.UnexpectedConversionError(
|
||||
"Encountered an I/O error during document to pixels conversion,"
|
||||
f" but the status of the conversion process is unknown (PID: {p.pid})"
|
||||
)
|
||||
return errors.exception_from_error_code(error_code)
|
||||
|
||||
@abstractmethod
|
||||
|
|
Loading…
Reference in a new issue