mirror of
https://github.com/containers/podman.git
synced 2025-11-30 01:58:46 +08:00
feat(exec): Add --no-session flag for improved performance
Fixes: #26588 For use cases like HPC, where `podman exec` is called in rapid succession, the standard exec process can become a bottleneck due to container locking and database I/O for session tracking. This commit introduces a new `--no-session` flag to `podman exec`. When used, this flag invokes a new, lightweight backend implementation that: - Skips container locking, reducing lock contention - Bypasses the creation, tracking, and removal of exec sessions in the database - Executes the command directly and retrieves the exit code without persisting session state - Maintains consistency with regular exec for container lookup, TTY handling, and environment setup - Shares implementation with health check execution to avoid code duplication The implementation addresses all performance bottlenecks while preserving compatibility with existing exec functionality including --latest flag support and proper exit code handling. Changes include: - Add --no-session flag to cmd/podman/containers/exec.go - Implement lightweight execution path in libpod/container_exec.go - Ensure consistent container validation and environment setup - Add comprehensive exit code testing including signal handling (exit 137) - Optimize configuration to skip unnecessary exit command setup Signed-off-by: Ryan McCann <ryan_mccann@student.uml.edu> Signed-off-by: ryanmccann1024 <ryan_mccann@student.uml.edu>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/containers/podman/v6/test/utils"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -616,4 +617,57 @@ RUN useradd -u 1000 auser`, fedoraMinimal)
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.OutputToString()).To(Equal("root"))
|
||||
})
|
||||
|
||||
It("podman exec with --no-session flag", func() {
|
||||
SkipIfRemote("The --no-session flag is not supported for remote clients")
|
||||
session := podmanTest.RunTopContainer("no_session_test")
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
execResult := podmanTest.Podman([]string{"exec", "--no-session", "no_session_test", "echo", "hello"})
|
||||
execResult.WaitWithDefaultTimeout()
|
||||
Expect(execResult).Should(ExitCleanly())
|
||||
Expect(execResult.OutputToString()).To(Equal("hello"))
|
||||
})
|
||||
|
||||
It("podman stop is not blocked by a long-running --no-session exec", func() {
|
||||
SkipIfRemote("The --no-session flag is not supported for remote clients")
|
||||
|
||||
ctrName := "no_session_lock_test"
|
||||
session := podmanTest.RunTopContainer(ctrName)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
execSession := podmanTest.Podman([]string{"exec", "--no-session", ctrName, "sleep", "30"})
|
||||
stopSession := podmanTest.Podman([]string{"stop", "-t", "5", ctrName})
|
||||
stopSession.WaitWithDefaultTimeout()
|
||||
Expect(stopSession).Should(ExitCleanly())
|
||||
Eventually(execSession, "5s").Should(Not(Exit(0)))
|
||||
})
|
||||
|
||||
It("podman exec --no-session exit codes", func() {
|
||||
SkipIfRemote("The --no-session flag is not supported for remote clients")
|
||||
|
||||
ctrName := "no_session_exit_code_test"
|
||||
session := podmanTest.RunTopContainer(ctrName)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
execResult := podmanTest.Podman([]string{"exec", "--no-session", ctrName, "sh", "-c", "exit 42"})
|
||||
execResult.WaitWithDefaultTimeout()
|
||||
Expect(execResult).Should(ExitWithError(42, ""))
|
||||
|
||||
execResult = podmanTest.Podman([]string{"exec", "--no-session", ctrName, "nonexistentcommand"})
|
||||
execResult.WaitWithDefaultTimeout()
|
||||
Expect(execResult).Should(ExitWithError(127, "OCI runtime attempted to invoke a command that was not found"))
|
||||
|
||||
execSession := podmanTest.Podman([]string{"exec", "--no-session", ctrName, "sleep", "30"})
|
||||
time.Sleep(2 * time.Second) // Give time for the first exec to start (CI is slow)
|
||||
killSession := podmanTest.Podman([]string{"exec", ctrName, "sh", "-c", "kill -9 $(pgrep sleep)"})
|
||||
killSession.WaitWithDefaultTimeout()
|
||||
Expect(killSession).Should(ExitCleanly())
|
||||
|
||||
execSession.WaitWithDefaultTimeout()
|
||||
Expect(execSession).Should(ExitWithError(137, ""))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user