Skip to content

fix: timeout for process.exec#4147

Open
vedranjukic wants to merge 2 commits intomainfrom
exec-timeout-fix
Open

fix: timeout for process.exec#4147
vedranjukic wants to merge 2 commits intomainfrom
exec-timeout-fix

Conversation

@vedranjukic
Copy link
Member

Description

Fixes the process.exec timeout not being respected. When a command like sleep 5; echo 'hello' is executed with timeout=2, the timeout error is only thrown after the full 5 seconds instead of after 2 seconds.

Root cause: The SDK wraps user commands as sh -c "echo '<base64>' | base64 -d | sh", creating a process tree (outer sh → pipe → inner shsleep 5). When the daemon's timeout fired, cmd.Process.Kill() only sent SIGKILL to the outer sh process. The grandchild processes inherited the pipe file descriptors and continued running, causing CombinedOutput() to block until they exited naturally.

Fix (two parts):

  1. Daemon (apps/daemon/pkg/toolbox/process/execute.go): Set Setpgid: true on the command so all child processes are placed in a new process group, then use syscall.Kill(-pid, SIGKILL) to kill the entire group on timeout. This ensures all descendant processes are terminated immediately.

  2. SDK (libs/sdk-python/src/daytona/_sync/process.py, libs/sdk-python/src/daytona/_async/process.py): Added _request_timeout=http_timeout(timeout) to the execute_command() call in exec(), matching the pattern already used by execute_session_command(). This prevents the HTTP client from blocking indefinitely if the daemon-side timeout fails to respond promptly.

Documentation

  • This change requires a documentation update
  • I have made corresponding changes to the documentation

Related Issue(s)

This PR addresses issue #2602

Signed-off-by: Vedran Jukic <vedran.jukic@gmail.com>
Made-with: Cursor
Signed-off-by: Toma Puljak <toma.puljak@hotmail.com>
@Tpuljak Tpuljak requested a review from MDzaja March 20, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants