K6 - error="Post \"{URL}": context deadline exceeded"

his error comes exactly after 1min, can someone help, please.
Already used below but still it gives error after exactly 1minute which is K6 by default timeout.

The response comes after 1.5min, so i need to increase the K6 timeout, please help.
what should I include in my code? I have recent version installed 0.26…

Environment

  • k6 version: - 0.26…
  • OS and version: MAC
  • Docker version and image, if applicable:

Actual Behavior

This error comes exactly after 1min, can someone help, please.
Already used below but still it gives error after exactly 1minute which is K6 by default timeout.

Response comes after 1.5min, so i need to increase the K6 timeout, please help.
what should I include in my code? I have recent version installed 0.26…

Steps to Reproduce the Problem

let params = {
timeout: 180000
};
{ "http.rw_timeout": "180s" }
setupTimeout: '180s'
K6_SETUP_TIMEOUT: '180s'
"tcp.connection_timeout":"180s",
"http.rw_timeout": "180s",
"log": "true",

using like this

Function PostWithValidJwt(endpoint, body, env) {
let res = http.post(endpoint, JSON.stringify(body), {headers: headers}, {
timeout: 180000, // 180 seconds
})
return res
}

Hi @pawansinha4u,

I don’t know why you’ve set all of those other things or where, as it’s not explained, but it doesn’t matter.

Your issue is simple: as per the k6 http.post documentation the params is the third parameter. You are giving it 4 parameters, that fourth one is getting ignored.
To fix it simply use one object as the third parameter:

let res = http.post(endpoint, JSON.stringify(body), {headers: headers, timeout:180000})

Hope this helps you!

p.s. Also, I am pretty sure Function should be lower case … but I guess this was a problem with you copy-pasting it.

1 Like

This was a great Help :slight_smile:
Thanks @mstoykov

1 Like

@mstoykov in my k6 script i am using like this:
export let options = {
stages: [
{ duration: ‘30s’, target: 50 }, // simulate ramp-up of traffic from 1 to x users over 20s.
{ duration: ‘60s’, target: 50 }, // stay at x users for 20s
{ duration: ‘20s’, target: 0 }, // ramp-down to 0 users
],
insecureSkipTLSVerify: true}

But i am still getting context timeout issue, is it a problem with the API i am testing?

Hi @prateekhasher,

What you have provided doesn’t tell me whether you have set timeout and whether your requests are hitting it, although they likely are if you are getting the context deadline message. Although also maybe you are hitting your duration+gracefulStop/Shutdown limits :man_shrugging: .

Your http_req_duration's max value should be w/e your timeout is (by default 60s, but you can change it as discussed above). If so, increasing your timeout might prevent this from happening but also will mean that your API is responding really slowly.

is it a problem with the API i am testing?

That is a question that you need to answer - is response time > 60s okay for this API ?, or is it not. In general, I would argue that no API should be taking this long, but in some cases, it is required so :man_shrugging: it’s on a case by case basis, basically.

p.s. it was probably better to create a new thread instead of ressurecting a year old one :wink: