K6 websockets gets disconnected iteration interrupted

I’m working with websockets and I’m having an issue with the WS being disconnected more or less 45 seconds into the test with the error
"error":"websocket: close 1005 (no status)"

From the server side, I don’t see any other hint apart from the socket being disconnected
disconnecting {"socket":"PFTnL9ZeI7GHScczAAAE"}

Maybe there is a timeout I’m not aware of? thank you!

using the setInterval I’m also seeing this message:

setInterval 1 was stopped because the VU iteration was interrupted
import { WebSocket } from 'k6/experimental/websockets';
import { setInterval } from 'k6/experimental/timers';

export const options = {
	scenarios: {
		my_scenario: {
      executor: 'constant-vus',
      vus: 1,
      duration: '5m',

export default async function () {
	// Connect to the WS and subscribe to the channel
  const ws = new WebSocket(`${webSocketURL}/socket/`);

  ws.onopen = () => {
    console.log('WebSocket connection established!');
    console.log('Subscribed to channel: ' + channel);

    const intervalId = setInterval(() => {
      ws.send(JSON.stringify({ event: 'SAY', message: `I'm saying hELLO` }));
    }, 3000); // say something every 3 seconds


  ws.onmessage = (message) => {
    if (message.data.includes(driver_channel)) {
      // Check if the data is present and matches the expected value
      check(message.data, { 'the received message matches the expected one': (value) => value.includes(JSON.stringify(redisData.data)) });

  ws.onerror = (e) => {
  ws.onclose = (e) => {
    console.log('WebSocket closed:', e);


Hi @rrubio2, welcome to the community forum!

This sounds like the server disconnects you. Maybe it is because of lack of ping messages.

The experimental websocket API does not support sending ping messages at the moment, so if you can try the old k6/ws one and send pings that will help us figure out if that is the issue.

You can use the experimental API to test this - here is the docs.

1 Like

@mstoykov : If I am not mistaken, the experimental websocket API also supports sending ping messages, just doesn’t send it automatically.

Ah, yes - you are correct @bandorko. I went to check that and saw the issue and then didn’t read the rest :man_facepalming:.

1 Like

Hey! Thanks for the info @mstoykov

I tried sending pings every second just to validate, but I’m still experiencing the disconnection. The server side is implemented with http://socket.io/ do you know if there is something else I need to do from the K6 side for a socket.io connection?

socket.io isn’t supported directly and likely never will as it is not a standard.

There is a wrapper provided by a community member listed in this issue. I have to say that I have not tried it, but there was one for k6/ws (the current in stdlib library) and it did work for some basic case years ago. So I can only expect this one works as well.