Last active
July 7, 2022 23:59
-
-
Save pravinchandar/ce019b20425dd6d41cf2790a312b8469 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // badTransformations keeps track of expr that resulted in the jqworker process | |
| // getting killed. | |
| // | |
| // Need to set a TTL (or some eviction policy) on the map so its growth is deterministic. | |
| var badTransformations = make(map[string]int) | |
| // JqTransform runs transformation on the jqserver | |
| func JqTransform(rpcClient *rpc.Client, input SomeInput) (*SomeOutput, error) { | |
| if badTransformations[params.Expression] == 3 { | |
| return nil, errors.New("skipping potential resource exhaustive transformation") | |
| } | |
| output := &SomeOutput{} | |
| err := rpcClient.Call("Jqserver.Evaluate", input, output) | |
| if err != nil { | |
| // errors.Is() don't work because | |
| // | |
| // https://pkg.go.dev/net/rpc#pkg-overview | |
| // | |
| // The method's return value, if non-nil, is passed back as a | |
| // string that the client sees as if created by errors.New. If an | |
| // error is returned, the reply parameter will not be sent back to | |
| // the client. | |
| if err.Error() == "resource limit exceeded" { | |
| badTransformations[params.Expression] += 1 | |
| } | |
| } | |
| return output, err | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment