google / google/go-jsonnet

Support for stdlib context (cancellation / timeouts)

Open
#729 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.