Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec()'s timeout doesn't result in TimeoutError on busybox images #15

Open
craigwalton-dsit opened this issue Dec 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@craigwalton-dsit
Copy link
Collaborator

It seems that busybox has a simpler version of timeout which behaves differently.

pod = Pod("agent-env-7ycxi9fs-busybox-0", "agent")
result = await pod.exec(["sleep", "10"], timeout=1)
print(result)

This exits with exit code 143 (128 + 15 [SIGTERM]) rather than 124.

Note: the timeout does still kick in, but doesn't manifest itself as a raised TimeoutError, rather just an ExecResult with success false.

We could recognise 143 in addition to 128 as signalling a timeout error e.g.

# 124 is the exit code for the GNU Coreutils `timeout` command. Busybox's
# implementation of the `timeout` command results in 128 + 15 (SIGTERM) = 143.
if timeout is not None and result.returncode in (124, 143):

but this would incorrectly classify some commands which are killed in ways unrelated to timeout errors as TimeoutErrors. Here is an example of an agent command accidentally killing itself - because pkill -f python3 matches itself (because the command was /bin/bash -c "<the agent code which includes "python3" as a string>).

# Start the Python HTTPS server in the background
python3 -c "
import http.server
import ssl
import threading

def run_server():
    httpd = http.server.HTTPServer(('0.0.0.0', 4443), http.server.SimpleHTTPRequestHandler)
    httpd.socket = ssl.wrap_socket(httpd.socket, certfile=\\'secure.com.crt\\', keyfile=\\'secure.com.key\\', server_side=True)
    print(\\'Server running on https://0.0.0.0:4443\\')
    httpd.serve_forever()

server_thread = threading.Thread(target=run_server)
server_thread.start()
" &

# Wait for the server to start
sleep 2

# Try to connect to the server using curl
curl -k https://localhost:4443

# Stop the Python server
pkill -f "python3 -c"
@craigwalton-dsit craigwalton-dsit added the bug Something isn't working label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant