Download file request returns 0 code status Request Failed error="context deadline exceeded"

Hi there! I’ve got two questions/concerns

  • First one:
    I’m load testing a download file feature on my app and I’m getting randomly (but most of the times) a 0 code status and Request Failed error="context deadline exceeded" error message. In stead of the 200 status code.
    The file is a .zip file and is download by a GET request:

I’ve noted that these requests fail when response time duration is < 60000. (console.log(res.timings.duration). Don’t know if this is related or not to that error.

  • My second question: Is there a way to store the file in a variable to check that the file has been downloaded?
    And is there a way also to check not only how long it takes to process the download http request but also to know how long it takes for the browser to download that file?

Thanks in advance!

Hi there, sorry for the delayed response.

I think you meant that you’re seeing the requests fail if duration is > 60000, not < 60000. If so, you’re hitting the 60s default request timeout, see the documentation. You can increase this on a per-request basis by passing a higher value in the http.get() params object, e.g. to set it to 5 minutes: http.get(myURL, { timeout: 300000 }).

In general we advise against downloading files in your tests and encourage using the discardResponseBodies option, since not doing so would result in increased memory usage, which could impact your test depending on the environment. When you’re downloading files in your k6 scripts you’re mostly testing the network connection itself rather than the service, which k6 is not that well suited for.

To answer your second question, if you don’t use discardResponseBodies, you can access the downloaded data using the Response.body field. Note that if your file is large (e.g. several MBs) you’ll have considerable memory penalty for each VU that downloads it, and because of some limitations with handling binary data there’s not much you can do with it besides passing it to another request for uploading, for example.

also to know how long it takes for the browser to download that file?

k6 does not run in a browser nor it behaves like one in most cases. The res.timings.duration value as you’ve been checking it so far will tell you the time it took for the GET request or download to complete.

Hope this helps,



@imiric Hi Ivan, what you suggested did the trick. I just had to do a little tweak so we are good! :slight_smile:

groupWithDurationMetric("Download Device Agent", function() {
    let req, res;
    req = [{
      "method": "get",
      "url": `https://my/download/path/download_file`,
      "params": {
        "cookies": {
        "headers": {
        discardResponseBodies: true,
        timeout: 600000

Thanks again to you and the k6 team that always give to the community a helping hand!

1 Like