From 0d708a528fad83efed27679bcab7a122b90e9db4 Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Tue, 30 Jul 2024 14:43:49 +0200 Subject: [PATCH] Revert "fix(jsonnet): add configurable timeout (#798)" This reverts commit 287b4d904bf5a21ef2ba61ed885609554b673a10. --- jsonnetsecure/jsonnet.go | 23 ++++------------------- jsonnetsecure/jsonnet_pool.go | 23 ++++++++++------------- jsonnetsecure/jsonnet_processvm.go | 11 +++++------ 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/jsonnetsecure/jsonnet.go b/jsonnetsecure/jsonnet.go index c3341c5e..0cf7ead6 100644 --- a/jsonnetsecure/jsonnet.go +++ b/jsonnetsecure/jsonnet.go @@ -9,18 +9,11 @@ import ( "path" "runtime" "testing" - "time" "github.com/google/go-jsonnet" ) type ( - evaluationOptions struct { - evalTimeout time.Duration - } - - EvaluationOptionModifier func(*evaluationOptions) - VM interface { EvaluateAnonymousSnippet(filename string, snippet string) (json string, formattedErr error) ExtCode(key string, val string) @@ -38,11 +31,10 @@ type ( } ProcessVM struct { - ctx context.Context - path string - args []string - execTimeout time.Duration - params processParameters + ctx context.Context + path string + args []string + params processParameters } vmOptions struct { @@ -51,7 +43,6 @@ type ( args []string ctx context.Context pool *pool - execTimeout time.Duration } Option func(o *vmOptions) @@ -79,12 +70,6 @@ func WithProcessIsolatedVM(ctx context.Context) Option { } } -func WithExecTimeout(timeout time.Duration) Option { - return func(o *vmOptions) { - o.execTimeout = timeout - } -} - func WithJsonnetBinary(jsonnetBinaryPath string) Option { return func(o *vmOptions) { o.jsonnetBinaryPath = jsonnetBinaryPath diff --git a/jsonnetsecure/jsonnet_pool.go b/jsonnetsecure/jsonnet_pool.go index 498562af..ec395113 100644 --- a/jsonnetsecure/jsonnet_pool.go +++ b/jsonnetsecure/jsonnet_pool.go @@ -5,7 +5,6 @@ package jsonnetsecure import ( "bufio" - "cmp" "context" "encoding/json" "io" @@ -24,12 +23,11 @@ import ( type ( processPoolVM struct { - path string - args []string - ctx context.Context - params processParameters - execTimeout time.Duration - pool *pool + path string + args []string + ctx context.Context + params processParameters + pool *pool } Pool interface { Close() @@ -185,7 +183,7 @@ func (vm *processPoolVM) EvaluateAnonymousSnippet(filename string, snippet strin defer otelx.End(span, &err) // TODO: maybe leave the timeout to the caller? - ctx, cancel := context.WithTimeout(ctx, cmp.Or(vm.execTimeout, 1*time.Second)) + ctx, cancel := context.WithTimeout(ctx, 1*time.Second) defer cancel() params := vm.params @@ -224,11 +222,10 @@ func NewProcessPoolVM(opts *vmOptions) VM { ctx = context.Background() } return &processPoolVM{ - path: opts.jsonnetBinaryPath, - args: opts.args, - ctx: ctx, - pool: opts.pool, - execTimeout: opts.execTimeout, + path: opts.jsonnetBinaryPath, + args: opts.args, + ctx: ctx, + pool: opts.pool, } } diff --git a/jsonnetsecure/jsonnet_processvm.go b/jsonnetsecure/jsonnet_processvm.go index 9ae4aaa5..de5567c0 100644 --- a/jsonnetsecure/jsonnet_processvm.go +++ b/jsonnetsecure/jsonnet_processvm.go @@ -5,7 +5,6 @@ package jsonnetsecure import ( "bytes" - "cmp" "context" "encoding/json" "fmt" @@ -24,10 +23,9 @@ import ( func NewProcessVM(opts *vmOptions) VM { return &ProcessVM{ - path: opts.jsonnetBinaryPath, - args: opts.args, - ctx: opts.ctx, - execTimeout: opts.execTimeout, + path: opts.jsonnetBinaryPath, + args: opts.args, + ctx: opts.ctx, } } @@ -37,11 +35,12 @@ func (p *ProcessVM) EvaluateAnonymousSnippet(filename string, snippet string) (_ defer otelx.End(span, &err) // We retry the process creation, because it sometimes times out. + const processVMTimeout = 1 * time.Second return backoff.RetryWithData(func() (_ string, err error) { ctx, span := tracer.Start(ctx, "jsonnetsecure.ProcessVM.EvaluateAnonymousSnippet.run") defer otelx.End(span, &err) - ctx, cancel := context.WithTimeout(ctx, cmp.Or(p.execTimeout, 1*time.Second)) + ctx, cancel := context.WithTimeout(ctx, processVMTimeout) defer cancel() var (