Unexpected EOF when proxy is used

I’m getting and unexpected EOF error with a proxy enabled. Without the proxy the test runs successfully. Using curl I can confirm that my proxy settings are correct. Since the proxy certificates are self-signed, I use -k with curl and insecureSkipTLSVerify option in the test script.

k6 --version
k6 v1.4.2 (commit/5b725e8a6a, go1.25.4, linux/amd64)

Here is my test file:

import http from "k6/http";
import { sleep } from "k6";

export const options = {
    httpDebug: 'full',
    insecureSkipTLSVerify: true,
};


export default async function (context) {
    http.get('https://quickpizza.grafana.com');
    sleep(1);
}

Here is how I test my parameters. curl returns correct result

export HTTPS_PROXY=https://user:password@proxy.io:60000
curl -k https://quickpizza.grafana.com

But the k6 fails when the HTTPS_PROXY env is set:

k6 run ./scenarios/demo-proxy.js      

         /\      Grafana   /‾‾/  
    /\  /  \     |\  __   /  /   
   /  \/    \    | |/ /  /   ‾‾\ 
  /          \   |   (  |  (‾)  |
 / __________ \  |_|\_\  \_____/ 

     execution: local
        script: ./scenarios/demo-proxy.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Request:
GET / HTTP/1.1
Host: quickpizza.grafana.com
User-Agent: Grafana k6/1.4.2
Accept-Encoding: gzip

  group= iter=0 request_id=19c53492-f47d-4809-9c0e-e75f0e8f6dcb scenario=default source=http-debug vu=1
WARN[0000] Request Failed                                error="Get \"https://quickpizza.grafana.com\": unexpected EOF"


  █ TOTAL RESULTS 

    HTTP
    http_req_duration....: avg=0s   min=0s   med=0s   max=0s   p(90)=0s   p(95)=0s  
    http_req_failed......: 100.00% 1 out of 1
    http_reqs............: 1       0.832024/s

    EXECUTION
    iteration_duration...: avg=1.2s min=1.2s med=1.2s max=1.2s p(90)=1.2s p(95)=1.2s
    iterations...........: 1       0.832024/s
    vus..................: 1       min=1      max=1
    vus_max..............: 1       min=1      max=1

    NETWORK
    data_received........: 3.7 kB  3.1 kB/s
    data_sent............: 1.8 kB  1.5 kB/s




running (00m01.2s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m01.2s/10m0s  1/1 iters, 1 per VU

I suspect the issue may be related to handling self‑signed certificates when using a proxy.

Is there a recommended way to fix or work around this issue when running k6 with a proxy and self‑signed certificates?

Hi @ilyanvu,

First of all, sorry for the big delay on the response, I lost track of this and never came back… until now!!

I tried to reproduce the issue you’re facing with mitmproxy and stunnel, but I haven’t been able to. It just works :person_shrugging:

So, I guess the main difference here might be the proxy in-use. Would you be able to share what software do you use as proxy? Also, note that k6 relies on http.ProxyFromEnvironment for proxying requests through the proxy defined with HTTPS_PROXY. So, perhaps another check we could try is.. can you run a small Go program and see if it successfully manages to make an HTTP(S) request through your proxy by using the environment variable.

Aside from that, I don’t know what else could be going work. As far as I know, we use a single TLSClientConfig that covers both proxy TLS and target TLS, and so the insecureSkipTLSVerify option should also apply to both, which in theory is what I tried to confirm with `stunnel`, as mentioned above.

Again, apologies for the delay.. and for not being able to find out what’s going wrong. But I’ll be happy to try to help you again if you have any other insight.