{"record":{"id":"38f2c421c5b2d58f","repo":"ory/hydra","slug":"failed-to-run-jsonnet-within-1s-filename-s","errorCode":null,"errorMessage":"failed to run jsonnet within 1s: filename=%s","messagePattern":"failed to run jsonnet within 1s: filename=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/jsonnetsecure/jsonnet_pool.go","lineNumber":269,"sourceCode":"\tctx, span := tracer.Start(vm.ctx, \"jsonnetsecure.processPoolVM.EvaluateAnonymousSnippet\", trace.WithAttributes(attribute.String(\"filename\", filename)))\n\tdefer otelx.End(span, &err)\n\n\tparams := vm.params\n\tparams.Filename = filename\n\tparams.Snippet = snippet\n\tpp, err := json.Marshal(params)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"jsonnetsecure: marshal\")\n\t}\n\n\tctx = context.WithValue(ctx, contextValuePath, vm.path)\n\tctx = context.WithValue(ctx, contextValueArgs, vm.args)\n\tworker, err := vm.pool.puddle.Acquire(ctx)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"jsonnetsecure: acquire\")\n\t}\n\n\tctx, cancel := context.WithTimeoutCause(ctx, 1*time.Second, errors.Errorf(\"failed to run jsonnet within 1s: filename=%s\", filename))\n\tdefer cancel()\n\tresult, err := worker.Value().eval(ctx, pp)\n\tif err != nil {\n\t\tworker.Destroy()\n\t\treturn \"\", errors.Wrap(err, \"jsonnetsecure: eval\")\n\t} else {\n\t\tworker.Release()\n\t}\n\n\tif strings.HasPrefix(result, \"ERROR: \") {\n\t\treturn \"\", errors.New(\"jsonnetsecure: \" + result)\n\t}\n\n\treturn result, nil\n}\n\nfunc NewProcessPoolVM(opts *vmOptions) VM {\n\tctx := opts.ctx","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/jsonnetsecure/jsonnet_pool.go#L251-L287","documentation":"EvaluateAnonymousSnippet runs a jsonnet snippet in a separate worker process obtained from a puddle resource pool, with a hard 1-second context timeout. If the worker does not finish evaluating the snippet within 1s, the context deadline fires and this error (attached via WithTimeoutCause) surfaces through the 'jsonnetsecure: eval' wrap. It exists to protect the host from runaway or pathological jsonnet programs that would otherwise hang the caller.","triggerScenarios":"Calling EvaluateAnonymousSnippet (vm.pool.puddle.Acquire path, oryx/jsonnetsecure/jsonnet_pool.go:269) with a snippet whose evaluation — or the wait for a free worker from the pool — takes longer than 1 second. Also fires if the pool is exhausted and Acquire blocks until the deadline.","commonSituations":"Snippets with large generated data, deep recursion, expensive native functions, or std.parseJson on big payloads. Also occurs under load when all jsonnet worker processes are busy so the 1s budget is consumed while waiting to acquire a worker.","solutions":["Simplify/optimize the jsonnet snippet: reduce recursion, avoid generating very large structures, precompute data outside jsonnet.","Reduce concurrent usage of the pool or increase the number of jsonnet worker processes so Acquire does not stall.","Raise the 1s timeout in a fork of jsonnetsecure (the timeout is currently hardcoded in jsonnet_pool.go).","Catch the error and surface a clear 'jsonnet evaluation timed out' message to the end user instead of retrying immediately."],"exampleFix":"// before\nout, err := vm.EvaluateAnonymousSnippet(\"config.jsonnet\", bigSnippet) // times out at 1s\n// after\nsmallSnippet := extractOnlyNeededFields(bigSnippet)\nout, err := vm.EvaluateAnonymousSnippet(\"config.jsonnet\", smallSnippet)","handlingStrategy":"try-catch","validationCode":"// Go: nothing to validate before; keep snippets small\nif len(snippet) > 100*1024 {\n    return errors.New(\"jsonnet snippet too large for 1s evaluation budget\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"failed to run jsonnet within 1s\") {\n        return fmt.Errorf(\"jsonnet evaluation timed out; simplify the snippet\")\n    }\n    return err\n}","preventionTips":["Keep jsonnet snippets small and free of deep recursion or huge data generation.","Avoid many concurrent EvaluateAnonymousSnippet calls that starve the worker pool.","Benchmark snippets in CI with a 1s budget so regressions are caught early."],"tags":["timeout","jsonnet","context-deadline"],"backgroundTag":"operation-timed-out","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}