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

panics in k6 extension only skip an iteration instead of failing the test or iteration #2354

Closed
geekflyer opened this issue Jan 27, 2022 · 2 comments · Fixed by #2453
Closed
Assignees
Labels
bug evaluation needed proposal needs to be validated or tested before fully implementing it in k6
Milestone

Comments

@geekflyer
Copy link

geekflyer commented Jan 27, 2022

Brief summary

Currently when a k6 extension panics, the k6 runtime "catches" the panic, simply skips the iteration and logs an error message like:

"time="2022-01-26T14:22:12-05:00" level=error msg="a panic occurred in VU code but was caught: record on line 1373: wrong number of fields" executor=constant-vus scenario=default"

There is no reasonable way to programmatically catch or report extension panics in k6 and apart from the log message they are essentially like a "silent" error.
For example if a load test has 10 iterations and all of them panic, k6 still considers the load test as a whole as successful.

k6 version

v0.35.0

OS

cross platform

Docker version and image (if applicable)

No response

Steps to reproduce the problem

create an extension method that instantly panics and call this method from a JS script

Expected behaviour

any (combination?) of these:

  • A panic bubbles up to the k6 JS layer as JS error and can be handled or ignored there
  • A panic stops the iteration but makes the iteration count as an "error" somewhere
  • A panic fails the k6 process with a non-zero exit code immediately

Actual behaviour

the k6 runtime "catches" the panic, simply skips the iteration and logs an error message like "time="2022-01-26T14:22:12-05:00" level=error msg="a panic occurred in VU code but was caught: record on line 1373: wrong number of fields" executor=constant-vus scenario=default". Otherwise it continues "as if" the iteration or loadtest was successful.

@geekflyer geekflyer added the bug label Jan 27, 2022
@na--
Copy link
Member

na-- commented Jan 27, 2022

Very good points... 🤔

A panic bubbles up to the k6 JS layer as JS error and can be handled or ignored there

I don't think this is possible, since a panic in VU code will generally interrupt the whole JS VM execution 😕 And even if it's technically possible, if there's a chance it leads to undefined behavior, we should probably avoid this approach unless we are absolutely sure it can work reliably.

  • A panic stops the iteration but makes the iteration count as an "error" somewhere
  • A panic fails the k6 process with a non-zero exit code immediately

These are somewhat connected to #877 and #1769. If Go panics emit an interrupted_iteration{cause:panic} metric, we can easily add a threshold that aborts the script based on that sub-metric 🤔

@na-- na-- added the evaluation needed proposal needs to be validated or tested before fully implementing it in k6 label Jan 27, 2022
@na-- na-- added this to the v0.38.0 milestone Mar 29, 2022
@olegbespalov
Copy link
Contributor

Hey @geekflyer !

We adjusted the behavior of how k6 treats panic. It should abort the execution. Could you please validate if that resolves your needs?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug evaluation needed proposal needs to be validated or tested before fully implementing it in k6
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants