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

ExecResult::exit_code returns None due to command not finishing #744

Open
tqwewe opened this issue Sep 30, 2024 · 3 comments
Open

ExecResult::exit_code returns None due to command not finishing #744

tqwewe opened this issue Sep 30, 2024 · 3 comments
Labels
docs question Further information is requested

Comments

@tqwewe
Copy link

tqwewe commented Sep 30, 2024

The ExecResult type returned from ContainerAsync::exec does not seem to represent a the command being completed, instead it returns before the executed command completes.

I would assume I can use ExecResult::exit_code().await to wait for the command to fully run and get the exit code, but instead it returns an Option::None when the command has not completed.

One workaround I found is to call ExecResult::stdout_to_vec().await and ExecResult::stderr_to_vec().await to stream the outputs until completion before calling ExecResult::exit_code().await. However this is far from ideal, as I need to await both these streams in order to be sure the command has completed. It would be nice if there's a ExecResult::wait().await method, or the ExecResult::exit_code().await command waits before returning the code.

@DDtKey
Copy link
Collaborator

DDtKey commented Sep 30, 2024

It's generally expected, see the documentation for ExecResult::exit_code

Returns the exit code of the executed command. If the command has not yet exited, this will return None.

In order to achieve your goal you need to utilize with_cmd_ready_conditions to specify what you're waiting for. Particularly - CmdWaitFor::exit_code

Did you try?

I guess it's worth to add mention of with_cmd_ready_condition as part of ExecResult documentation 🤔

But the interface is expected, since sometimes it's necessary to spawn some background command without waiting for its results. Or in case you want to have some custom logic which periodically checks the status of the command.

@DDtKey DDtKey added the question Further information is requested label Sep 30, 2024
@tqwewe
Copy link
Author

tqwewe commented Sep 30, 2024

Ah no I actually completely missed the ready condition for commands 🤦🏿 my mistake.

I see CmdWaitFor::exit_code, which is probably what I want. Though it seems like there's not really any wait for condition for waiting for the command to execute completely no matter the exit code?

@DDtKey
Copy link
Collaborator

DDtKey commented Sep 30, 2024

Yes, you're right. It will wait for particular exit code and will return an error if actual one doesn't match with expected (ExecError::ExitCodeMismatch).

We can consider shortcut "WaitCmdFor::Finish" which will ignore the code. However even right now it should be possible by handling the error returned

@DDtKey DDtKey added the docs label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants