Skip to content

Commit

Permalink
Revert "fix(jsonnet): add configurable timeout (#798)"
Browse files Browse the repository at this point in the history
This reverts commit 287b4d9.
  • Loading branch information
alnr committed Aug 6, 2024
1 parent 2d48764 commit 0d708a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
23 changes: 4 additions & 19 deletions jsonnetsecure/jsonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -51,7 +43,6 @@ type (
args []string
ctx context.Context
pool *pool
execTimeout time.Duration
}

Option func(o *vmOptions)
Expand Down Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions jsonnetsecure/jsonnet_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package jsonnetsecure

import (
"bufio"
"cmp"
"context"
"encoding/json"
"io"
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand Down
11 changes: 5 additions & 6 deletions jsonnetsecure/jsonnet_processvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package jsonnetsecure

import (
"bytes"
"cmp"
"context"
"encoding/json"
"fmt"
Expand All @@ -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,
}
}

Expand All @@ -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 (
Expand Down

0 comments on commit 0d708a5

Please sign in to comment.