Make `podman exec --no-session` not use Conmon #30411
@giuseppe Mind taking a look at the OCI runtime bits?
please also specify --detach as it would break with runc:
bin/podman exec --no-session=true -t -l echo hi
exec failed: cannot use console socket if runc will not detach or allocate tty
Error: OCI runtime error: runc: exec failed: cannot use console socket if runc will not detach or allocate tty
do we need to keep the container lock here to prevent a removal to rm the exec bundle and leak the bundle dir?
another question: instead of duplicating the tty handling, could we just pass "tty: true" to the OCI runtime and let it deal with the tty? The only disadvantage is that the runtime exec will stay around (but it is not a big cost IMO)
Requested changes.
This is really nice. I've checked the overall logic in high-level and it makes sense. I will do detailed review later :-).
I think there's a risk, but holding the container lock would destroy the performance benefits, so I think we have to be willing to live with it? I could mention the risk in the manpage...
RE: tty=true - it had a few issues with attach in my testing so I avoided it - control characters being eaten during attach, for example.
so could we avoid the MkdirAll and create only the directories we need (so that it is not creating parent directories that were removed)?
is that an issue in crun?
generally speaking all state check outside a lock are incorrect. by the time we checked this the container can be in any other state already.
what is preventing some other process from picking the same id randomly?
the mkdir should not use MkdirAll(), it should return an error is the session directory already exists to avoid id conflicts
why is this comment removed
There is nothing reaping the child process here is there? All process stays as zombie until the main one exists?
Also that is a big no for the podman system service
Not a full review, overall this feels quite hacky. Do we really need to detach? Seems a lot simpler not doing that and just waiting for the crun exec parent we just spawned?
Then we can read the exit code normally and do not need to be supereaper. Also I agree not having to deal with the tty would be nice so using the --tty option would be nicer IMO.
I think the risk already exists is the problem with the session / process.json file leaking. Could we in theory pass a pipe instead? Like give /proc/self/fd/x to child as path and open the read side of the pipe there? Of course it would need a another sender goroutine as the content could be larger then the max buffer size of the pipe
I mean, they could, but it's a 256-bit random integer. If we have collisions, the universe hates us.
It would certainly be a lot simpler if we could drop detach and the subreaper bits
Regarding TTY - I think it's kind of important to retain, the expectation is that all usage is going to go through exec in this case, including debugging.
giuseppe
mheon
This was a goal for
--no-sessionfrom the beginning. This is meant for tasks that aren't meant to be visible via typicalpodman execAPIs (e.g. healthchecks or high-throughput HPC applications) where we don't need the features or complexity that Conmon brings to the table. Running quickly, with as few resources as possible, is the most critical portion.Losing this, we lose the ability to attach to or detach from a running session - which we didn't really want or need anyway for sessionless exec. We lose the ability to capture exit codes if Podman itself exits - again, not something we really wanted. In exchange, we remove the overhead of an extra fork-exec and an extra running monitor process we have no use for.
On top of this, stop taking locks in the happy path. The only thing we needed it for was syncContainer() potentially detecting a container that had exited before we started and not had its cleanup process fire yet. Just updating state from the DB to check if the container is running doesn't require that, and the only thing we lose is a less clear error message from the OCI runtime instead of from Podman when we go to start the session. In case of an error like that, we still run a syncContainer() to pick up the state change that occurred. This approach avoids any modification to the Container struct, and should be proof against concurrency issues as such.
Switch healthchecks over to the new codepath, because they don't really need anything Conmon offers (and having them not take locks is potentially a pretty big net win in high-throughput environments with lots of containers with healthchecks running at the same time - commands like
podman psa lot less likely to get hung grabbing locks).Total performance increase is in the vicinity of 500% (sequential
podman execcommands) to 650% (concurrently starting 100podman exec) on my system, per testing with included scripts.<!-- Thanks for sending a pull request! -->
Does this PR introduce a user-facing change?
<!--
Write
Noneif there are no user-facing changes, otherwise enter your release note below.Include "action required" if users need to take action when upgrading.
-->
``
release-notepodman exec --no-sessionThe
command no longer uses Conmon, and instead directly invokes the OCI runtime. Performance on starting large quantities of exec sessions has risen by approximately 500%.
``