-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
Piping task timeout #243
Piping task timeout #243
Conversation
Hmm what if we make it possible to configure the command to not throw on cancellation and instead use |
When executing a command, it's impossible to know how long it will take to complete. If a cancellation token is set and fired while the command is still running, it will force pipingTask an immediate finish, potentially resulting in lost output logs. It's important to note that the cancellation token will only work if it's fired manually by the client, such as in reaction to some expected output on process finish. Otherwise, using To avoid this, it's better to allow some time for the |
So is the difference from the current cancellation behavior such that the |
When you use graceful/forceful cancellation tokens, they send interrupt/kill signal to process, then forceful cancellation token is used to finish piping task. So you could use forceful cancellation token to cancel the process and piping, but then
This PR resolves above issues. |
Hi @Tyrrrz, what do you think about merging this request? We use it in our production for some time and it works fine. If you'd like to, I can provide more tests, but the behavior added here doesn't break existing features. |
Hi @dmilosz Sorry, I can't find the time to dedicate to this yet. I have it on my todo list and I will come back to it when I'm a bit less busy. |
Hi @dmilosz Sorry for the wait. I think instead of a timeout, it's actually better to have an on/off setting, like you originally suggested in the linked issue. I doubt there's value in timeouts other than Also, for consistency with // Wait for pipes, default
Cli.Wrap(...).WithCompletion(CommandCompletion.PipesClosed);
// Don't wait for pipes, only for process exit
Cli.Wrap(...).WithCompletion(CommandCompletion.ProcessExited); |
Parent process may write a lot of logs to std output. If we just wait for process exit, we can possibly not handle all logs from it. With timeout, I can set it to X seconds, so I make sure that when child processes are launched, ale logs from parent process are handled (if my X seconds are enough to catch it). |
I see what you mean. I don't like introducing a timeout because, like you said, it does not provide any guarantees that the streams will be fully read by then. Set it too low and you may still miss some data, set it too high and you might wait too long. It might also be extra problematic if the child process does not write much or anything to the output streams, because then they may never be flushed until the child process exits too. This depends on the platform, though. Overall, I believe there are too many problematic aspects about this implementation that makes it difficult to support it as a first class feature in the library. Maybe we can find a better solution eventually. |
This timeout is only relevant in cases where the main process quickly finishes but launches other processes that continue running indefinitely. It's not a breaking change and won't affect any existing implementations. Instead, it adds support for this specific scenario, allowing users to wait for output if they expect the main process to generate a significant amount of logs. I don't think it's problematic, but I understand the use case is rare one. |
Closes #241
It resolves the issue, by allowing to specify max timeout to wait for piping to be finished. By doing this way, we can customize how long to wait after the process is finished. The code throws exception, when waiting for piping exceeded timeout, which can be cached by client and it can be properly handled.
Timeout also gives flexibility for the client to give enough time to handle the output, so that it's not lost for the cases when child process is started, but it's important to read all output of the main process.
It's also a lot easier to create nice unit test for the behavior. Unfortunately, it .NET Framework behaves differently in the same case, so I had to exclude it in unit test. In .NET Framework, when main process is exited but child process is still running, the
Exited
event is not fired for some reason.Example from unit test:
Without
.WithPipingTimeout(TimeSpan.FromSeconds(1))
this test gets timeout after 10 seconds.