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

cmd/run: Optimize 'enter' and 'run' in the non-fallback case #813

Merged

Conversation

debarshiray
Copy link
Member

@debarshiray debarshiray commented Jun 25, 2021

Currently, the enter command involves two extra invocations of
podman exec to detect if the user's chosen shell and current working
directory are present inside the toolbox container. Each invocation is
sufficiently expensive to add a noticeable overhead to the enter and
run commands. Moreover, file system operations being inherently racy,
it's always better to detect errors and handle them instead of trying
to pre-emptively avoid them.

Therefore, this shuffles the code around to attempt the non-fallback
invocation, and then handle the errors by attempting a series of
fallbacks for the command and the current working directory.

Unfortunately, in case of a missing command, capsh(1) adds an extra
error message that seems difficult to get rid of:

  $ toolbox enter
  /bin/sh: /bin/zsh: No such file or directory
  Error: command /bin/zsh not found in container fedora-toolbox-34
  Using /bin/bash instead.

This will be used by the subsequent commit to optimize the 'enter' and
'run' commands in the non-fallback case, by attempting the fallback
only if an error was encountered by the main 'podman exec' invocation,
as opposed to pre-emptively setting up the fallback.

containers#813
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jun 25, 2021
Currently, the 'enter' command involves two extra invocations of
'podman exec' to detect if the user's chosen shell and current working
directory are present inside the toolbox container. Each invocation is
sufficiently expensive to add a noticeable overhead to the 'enter' and
'run' commands. Moreover, file system operations being inherently racy,
it's always better to detect errors and handle them instead of trying
to pre-emptively avoid them.

Therefore, this shuffles the code around to attempt the non-fallback
invocation, and then handle the errors by attempting a series of
fallbacks for the command and the current working directory.

containers#813
@debarshiray debarshiray force-pushed the wip/rishi/run-optimize-fallbacks branch from 41bea8c to 43a3222 Compare June 25, 2021 21:46
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jun 25, 2021
Currently, the 'enter' command involves two extra invocations of
'podman exec' to detect if the user's chosen shell and current working
directory are present inside the toolbox container. Each invocation is
sufficiently expensive to add a noticeable overhead to the 'enter' and
'run' commands. Moreover, file system operations being inherently racy,
it's always better to detect errors and handle them instead of trying
to pre-emptively avoid them.

Therefore, this shuffles the code around to attempt the non-fallback
invocation, and then handle the errors by attempting a series of
fallbacks for the command and the current working directory.

containers#813
@debarshiray debarshiray force-pushed the wip/rishi/run-optimize-fallbacks branch from 43a3222 to 3b57aac Compare June 25, 2021 22:08
@softwarefactory-project-zuul
Copy link

Build failed.

debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jun 25, 2021
Currently, the 'enter' command involves two extra invocations of
'podman exec' to detect if the user's chosen shell and current working
directory are present inside the toolbox container. Each invocation is
sufficiently expensive to add a noticeable overhead to the 'enter' and
'run' commands. Moreover, file system operations being inherently racy,
it's always better to detect errors and handle them instead of trying
to pre-emptively avoid them.

Therefore, this shuffles the code around to attempt the non-fallback
invocation, and then handle the errors by attempting a series of
fallbacks for the command and the current working directory.

Unfortunately, in case of a missing command, capsh(1) adds an extra
error message that seems difficult to get rid of:
  $ toolbox enter
  /bin/sh: /bin/zsh: No such file or directory
  Error: command /bin/zsh not found in container fedora-toolbox-34
  Using /bin/bash instead.

containers#813
@debarshiray debarshiray force-pushed the wip/rishi/run-optimize-fallbacks branch from 3b57aac to 11051a6 Compare June 25, 2021 23:04
Currently, the 'enter' command involves two extra invocations of
'podman exec' to detect if the user's chosen shell and current working
directory are present inside the toolbox container. Each invocation is
sufficiently expensive to add a noticeable overhead to the 'enter' and
'run' commands. Moreover, file system operations being inherently racy,
it's always better to detect errors and handle them instead of trying
to pre-emptively avoid them.

Therefore, this shuffles the code around to attempt the non-fallback
invocation, and then handle the errors by attempting a series of
fallbacks for the command and the current working directory.

Unfortunately, in case of a missing command, capsh(1) adds an extra
error message that seems difficult to get rid of:
  $ toolbox enter
  /bin/sh: /bin/zsh: No such file or directory
  Error: command /bin/zsh not found in container fedora-toolbox-34
  Using /bin/bash instead.

containers#813
@softwarefactory-project-zuul
Copy link

Build failed.

@debarshiray debarshiray merged commit 4536e2c into containers:main Jun 25, 2021
@debarshiray debarshiray deleted the wip/rishi/run-optimize-fallbacks branch June 25, 2021 23:29
err = fmt.Errorf("directory %s not found in container %s", workDir, container)
return err
}
} else {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't assume that an exit code of 127 from podman exec means that either the working directory or the command was absent. The given shell might also return with 127, which will get forwarded by podman exec, if the last command that was attempted inside the shell was absent. In such cases this will create a loop.

See #872

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