Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,12 @@ def _start_container(self) -> None:
str(self.host_port),
]

# Start the server process in the background in separate process group
# Start the server process in the background in separate process group.
# Without a log thread nothing reads a pipe, and a full pipe would block
# the server, so its output is discarded instead.
self._process = subprocess.Popen(
server_cmd,
stdout=subprocess.PIPE,
stdout=subprocess.PIPE if self.detach_logs else subprocess.DEVNULL,
stderr=subprocess.STDOUT,
text=True,
start_new_session=True,
Expand Down
16 changes: 16 additions & 0 deletions tests/workspace/test_apptainer_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ def test_apptainer_workspace_extra_bind_mounts(mock_apptainer_workspace, monkeyp
workspace._instance_name = None


def test_undrained_logs_do_not_block_server(mock_apptainer_workspace):
"""With detach_logs=False nothing reads the server's output, so no pipe."""
workspace, _ = mock_apptainer_workspace() # detach_logs=False

with patch(
"openhands.workspace.apptainer.workspace.subprocess.Popen",
return_value=Mock(stdout=None),
) as mock_popen:
workspace._start_container()

assert mock_popen.call_args.kwargs["stdout"] is subprocess.DEVNULL

workspace._process = None
workspace._instance_name = None


def test_failed_health_check_terminates_server_process(monkeypatch, tmp_path):
from openhands.workspace import ApptainerWorkspace

Expand Down
Loading