Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout support in wazero run cli #1173

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

evacchi
Copy link
Contributor

@evacchi evacchi commented Feb 27, 2023

  • ensure the module initialization function is evaluated
    regardless if it's WASI or GoJS
  • add a -timeout duration flag
  • ensure flag gets propagated to the rt config builder
    (also ensure cache flag gets propagated to the rt config builder)
  • print a message to stderr when the deadline is exceeded
  • configure GitHub Actions to use -timeout=10m flag
    instead of GHA's timeout-minutes: 10

Signed-off-by: Edoardo Vacchi evacchi@users.noreply.github.com

}

if err != nil {
if exitErr, ok := err.(*sys.ExitError); ok {
exit(int(exitErr.ExitCode()))
exitCode := exitErr.ExitCode()
if timeout > 0 && exitCode == sys.ExitCodeDeadlineExceeded {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need timeout >0? I guess sys.ExitCodeDeadlineExceeded won't be set if timeout == 0

exit(int(exitErr.ExitCode()))
exitCode := exitErr.ExitCode()
if timeout > 0 && exitCode == sys.ExitCodeDeadlineExceeded {
fmt.Fprintf(stdErr, "canceled: wasm binary '%s' exceeded timeout (%v)\n", wasmExe, timeout)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, although the error becomes slightly more cryptic:

error: module "" closed with context deadline exceeded (timeout 1ms)

I have still added the timeout

@@ -133,6 +134,11 @@ func doRun(args []string, stdOut io.Writer, stdErr logging.Writer, exit func(cod
"This may be specified multiple times. When <wasm path> is unset, <path> is used. "+
"For read-only mounts, append the suffix ':ro'.")

var timeout time.Duration
flags.DurationVar(&timeout, "timeout", 0*time.Second,
"if a wasm binary runs longer than the given duration, then panic. "+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for non gophers, the duration format for this string might not be common. Maybe add example here??

Copy link
Contributor Author

@evacchi evacchi Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message is tad longer now, but it should be good; basically I lifted the one in the Go docs for ParseDuration except the note about it being negative because it makes no sense: I also added a test to return an error in case of a negative value

@codefromthecrypt
Copy link
Contributor

also for another PR I think we should test ctrl-c (sigint) on an endless loop. Not sure, but maybe we'll end up needing context integration and a signal handle..

- ensure the module initialization function is evaluated
  regardless if it's WASI or GoJS
- add a `-timeout duration` flag
- ensure flag gets propagated to the rt config builder
  (also ensure cache flag gets propagated to the rt config builder)
- print a message to stderr when the deadline is exceeded
- configure GitHub Actions to use `-timeout=10m` flag
  instead of GHA's `timeout-minutes: 10`

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Comment on lines +96 to +100
c = c.WithCompilationCache(cache)
}

ctx := context.Background()
rt := wazero.NewRuntime(ctx)
rt := wazero.NewRuntimeWithConfig(ctx, c)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we forgot to use c here

Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree the desc is a little wordy now, but not too much and we can blame it on go ;)

good job!

@evacchi
Copy link
Contributor Author

evacchi commented Feb 28, 2023

also for another PR I think we should test ctrl-c (sigint) on an endless loop. Not sure, but maybe we'll end up needing context integration and a signal handle..

Unless I misunderstood, I think it already works? 🤔

go install ./cmd/wazero
wazero run cmd/wazero/testdata/infinite_loop.wasm

c-c works as expected (no change required)

@codefromthecrypt
Copy link
Contributor

sorry about ctrl-c I didn't know if it did or not (we should backfill a test. there's a similar one in func-e under the e2e directory). anyway different but similar topic though out of scope here!

@codefromthecrypt codefromthecrypt merged commit 5598e49 into tetratelabs:main Feb 28, 2023
@evacchi evacchi deleted the wazero-cli-timeout branch February 12, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants