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

Support canceling remote processes via context.Context #125

Open
kgadams opened this issue Feb 17, 2022 · 7 comments
Open

Support canceling remote processes via context.Context #125

kgadams opened this issue Feb 17, 2022 · 7 comments

Comments

@kgadams
Copy link
Contributor

kgadams commented Feb 17, 2022

Hi Brice,
I would like to have public access to the err member of the Command struct. This would make it possible to reimplement the Client.Run* methods out of package in a way that supports canceling via context.Context. Would you consider a PR to this effect?

@masterzen
Copy link
Owner

Sorry for the very late answer, but I would prefer to have a PR that adds support for passing a context.Context.

@kgadams
Copy link
Contributor Author

kgadams commented Apr 25, 2022

Okay, fair enough.
How do you want to go about this?

  • expansion of the interface with new functions (RunWithContext)?
  • change the existing interface (which would probably mean going for v2?)
  • similar to how http.Request does it (...WithContext()). However this seems to be getting out of favor with the go community, as you have to store the context in the struct.

@masterzen
Copy link
Owner

I think the RunWithContext would be enough for this small library. Internally, it's just a matter of checking if we have a context and calling the WithContext whenever needed.

@kgadams
Copy link
Contributor Author

kgadams commented Jun 8, 2022

Is this what you had in mind?
The external interface is unaffected, but for all exposed functions we now have an alternative that takes a context.Context as first argument.

@kgadams kgadams changed the title Public access to Command.err needed Support canceling remote processes via context.Context Jun 8, 2022
@PaulFarver
Copy link

@masterzen Would you be interested in a PR, where we pass the context to the http request as well with http.NewRequestWithContext, so we can control cancellation of the entire process.

@kgadams
Copy link
Contributor Author

kgadams commented Nov 1, 2022

@masterzen Would you be interested in a PR, where we pass the context to the http request as well with http.NewRequestWithContext, so we can control cancellation of the entire process.

Hi Paul, I toyed with that as well, however canceling the program on the remote machine requires a successful HTTP REST call, so that did not work out for me.

@PaulFarver
Copy link

Hi Paul, I toyed with that as well, however canceling the program on the remote machine requires a successful HTTP REST call, so that did not work out for me.

Hi Klaus-Georg, that's a good point. We should absolutely try not to leave processes hanging in the remote host.

I still think it's an issue that we can't cancel requests, though. If the remote host doesn't respond to http requests we have to wait for the os to give us an io timeout.

Just spitballing, but maybe if we split up the interface, so users could run each step separately with it's own context, so we're not lumping multiple requests into the same call.

Maybe this should be considered a separate issue?

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

No branches or pull requests

3 participants