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

REST API triggering of setup and teardown doesn't always time out correctly #869

Closed
na-- opened this issue Dec 14, 2018 · 1 comment
Closed

Comments

@na--
Copy link
Member

na-- commented Dec 14, 2018

I have the following k6 script:

import { sleep } from "k6";

const sleepTime = parseFloat(__ENV.sleep);

export function setup() {
    sleep(sleepTime);
    console.log("setup successful");
    return "setup successful";
}

export default function (data) {
    console.log("default with setup " + JSON.stringify(data));
}

export function teardown() {
    sleep(sleepTime);
    console.log("teardown successful");
}

If I execute it with k6 run -e sleep=11 xt.js (the default timeouts for the setup() and teardown() functions is 10 seconds), I consistently get the expected Engine error with a message setup: context cancelled at setup (...). Despite not changing the k6 exit code (link to issue about it) and the very poor error message (sigh), the timeout works consistently and aborts the script correctly.

When I run the script with k6 run -e sleep=11 --no-setup --no-teardown --paused xt.js on the other hand, and I trigger the setup execution via the k6 REST API with curl -i -XPOST http://127.0.0.1:6565/v1/setup, some of the time I correctly get HTTP/1.1 500 Internal Server Error with body {"errors":[{"status":"500","title":"Error executing setup","detail":"setup: context cancelled at setup (...)"}]}, but most of the time k6 actually ignores the timeout and I get HTTP/1.1 200 OK with a body {"data":{"type":"setupData","id":"default","attributes":{"data":"setup successful"}}}

Increasing the sleep time to 21 (k6 run -e sleep=21 --no-setup --no-teardown --paused xt.js for example) seems to somewhat ameliorate the issue, in that there are fewer 200 responses, but it still doesn't completely fix it! Splitting the sleep() call in the setup() function to sleep(sleepTime/2); sleep(sleepTime/2); on the other hand causes the issue to disappear completely, at least as far as I can test. So this seems to be some sort of channel select issue where the timeouts don't always register?

@mstoykov
Copy link
Contributor

mstoykov commented Jan 2, 2019

I have been able to reproduce this with setting GOMAXPROCS=1 otherwise I was having trouble.Running with GOMAXPROCS=2 I got 2 out of 100 runs and without it I didn't get a single 200 for about hour and half maybe two that I tried.

I guess your setup will lead to the same end result @na-- ?

mstoykov added a commit that referenced this issue Jan 4, 2019
Previously because of the way js interrupt works it was that the js vm
will not get interrupt signal for some time after the timeout has
happened. This would be especially true in cases of lower (1) cpu counts
or under heavy load.
Because calls from inside js to go code will return when the
context is *Done* we will probably still end setup/teardown functions in
approximately timeout time but it might not actually be marked as
timeouted.

To fix this after calls to js functions we check that the timeout has
been passed if setted. If this has happened we return a new specific
timeout error that can later be used to distinguish that timeout has
happened. There is also some additional code to catch that an actual
interrupt has happened and that it is because of timeout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants