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 for stdlib context (cancellation / timeouts) #729

Open
aeneasr opened this issue Aug 31, 2023 · 0 comments
Open

Support for stdlib context (cancellation / timeouts) #729

aeneasr opened this issue Aug 31, 2023 · 0 comments

Comments

@aeneasr
Copy link

aeneasr commented Aug 31, 2023

At the moment, we have no way of canceling vm.EvaluateAnonymousSnippet and similar functions. Because of this, there are several things that can't be done:

  1. Racing multiple JsonNet evaluations against each other, taking the first result, and canceling the rest.
  2. Kill long-running JsonNet evaluations. It is possible to build very slow JsonNet code with array comprehensions, infinite loops, and recursion. There is currently no way of killing such a script after X seconds or X MB of ram used.

There is a workaround such as sending SIGINT on the process, that however requires to execute each JsonNet snippet in a separate process, which is not feasable if thousands or millions of JsonNet executions have to be done per second.

For these reasons, it would be great if this library supported evaluation with contexts, for example:

ctx, cancel := context.WithTimeout(parent, time.Second)
defer cancel()

vm.EvaluateAnonymousSnippetContext(ctx, ...)

This isn't the first time that context handling was added to existing libraries this way - I think that's even the case for some of Go's stdlib functions.

Is this something you would consider being in the library? If so, we can also try to contribute such changes.

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

1 participant