Skip to content

Add --no-exit to keep running even after the subprocess exits#64

Merged
alexflint merged 2 commits into
mainfrom
no-exit
Jul 7, 2025
Merged

Add --no-exit to keep running even after the subprocess exits#64
alexflint merged 2 commits into
mainfrom
no-exit

Conversation

@alexflint

@alexflint alexflint commented Jul 7, 2025

Copy link
Copy Markdown
Member

A subprocess launched by httptap can "daemonize" itself (fork, detach itself with setsid, then fork again), in which case the subprocess launched by httptap will return, but other processes will still be running in the network namespace. At present, httptap exits when the immediate subprocess exits, leaving other such processes stranded in an isolated network namespace. Those processes will have no network connectivity, and the user won't see HTTP calls they make on the command line. This PR adds a simple workaround: a --no-exit flag that simple has httptap wait around until it is killed.

A good minimal way to reproduce this phenomenon is:

$ httptap -- setsid setsid curl http://httpbin.org/get
curl: (6) Could not resolve host: httpbin.org

A python example that illustrates a bit more what syscalls are at play is:

$ httptap -- python -c 'import os; import sys; import subprocess
if os.fork(): sys.exit()
os.setsid()
if os.fork(): sys.exit()
subprocess.run(["curl", "http://httpbin.org/get"])'
curl: (6) Could not resolve host: httpbin.org

An existing workaround is to put a "sleep infinity" into the command run by httptap:

$ httptap -- bash -c "setsid setsid curl http://httpbin.org/get; sleep infinity"
---> GET http://httpbin.org/get
<--- 200 http://httpbin.org/get (285 bytes)
...

The above works but is a bit obscure. With this PR this becomes:

$ httptap --no-exit -- setsid setsid curl http://httpbin.org/get                                                                      
---> GET http://httpbin.org/get
<--- 200 http://httpbin.org/get (285 bytes)

The user still has to press ctrl+c at the end.

#63

@alexflint alexflint changed the title Add --no-exit Add --no-exit to keep running even after the subprocess exits Jul 7, 2025
@alexflint alexflint merged commit e73fe59 into main Jul 7, 2025
1 check passed
@alexflint alexflint deleted the no-exit branch July 7, 2025 21:33
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.

1 participant