Skip to content

Commit cc7fe02

Browse files
committed
Honor executor timeout in Windows start() path
subprocess.run() on the Windows synchronous start path had no timeout, so a stuck pg_ctl could block indefinitely. Pass self._timeout (the configured mirakuru timeout in seconds) to subprocess.run(..., timeout=). Catch subprocess.TimeoutExpired — subprocess.run already kills the process before re-raising, so no extra cleanup is needed — and translate it to mirakuru.exceptions.TimeoutExpired so callers see the same exception type produced by the non-Windows path. Also imports TimeoutExpired from mirakuru.exceptions alongside the existing ProcessFinishedWithError import. Made-with: Cursor
1 parent 9fac771 commit cc7fe02

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

pytest_postgresql/executor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from typing import Any, Optional, TypeVar
3131

3232
from mirakuru import TCPExecutor
33-
from mirakuru.exceptions import ProcessFinishedWithError
33+
from mirakuru.exceptions import ProcessFinishedWithError, TimeoutExpired
3434
from packaging.version import parse
3535

3636
from pytest_postgresql.exceptions import ExecutableMissingException, PostgreSQLUnsupported
@@ -199,7 +199,12 @@ def start(self: T) -> T:
199199
self.logfile,
200200
*shlex.split(self.startparams),
201201
]
202-
result = subprocess.run(args, check=False, env=self.envvars)
202+
try:
203+
result = subprocess.run(args, check=False, env=self.envvars, timeout=self._timeout)
204+
except subprocess.TimeoutExpired as exc:
205+
# subprocess.run already killed the stuck pg_ctl process before
206+
# re-raising, so no additional cleanup is required here.
207+
raise TimeoutExpired(self, self._timeout) from exc
203208
if result.returncode != 0:
204209
raise ProcessFinishedWithError(self, result.returncode)
205210
return self

0 commit comments

Comments
 (0)