Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
K6 Websocket disconnects after 15 seconds

I’m having trouble running a K6 websocket for more than 15 seconds on 1 VU.

The code is from the documentation:

const socketUrl = `${resBody.url.replace('https', 'wss')}&id=${connectionId}`;

res = ws.connect(socketUrl, params, function (socket) {
    socket.on('open', function() {
        console.log('connected');
        
        socket.setInterval(function timeout() {
            socket.ping();
        }, 1000); 
        
        var payload = JSON.stringify({
            'protocol': 'json',
            'version': 1
        });
        socket.send(payload);           
    });
    socket.on('message', (data) => console.log('Message received: ', data));
    socket.on('close', () => console.log('disconnected'));
    socket.on('error', (e) => console.log('Error: ', e.error()));
    socket.on('ping',  function() {
        console.log('ping');
        socket.pong();
    });
    socket.on('pong', () => console.log('pong'));
    socket.on('priceupdates', (data) => console.log('PriceUpdates: ', data));

    socket.setTimeout(function () {
        console.log('Timeout');
        socket.close();
    }, 1000 * 60 * 100);
});
    
check(res, { 'status is 101': (r) => r && r.status === 101 });

Run command:

k6 run --vus 1 --iterations 1 --duration 1m --min-iteration-duration 30s live_prices.js

And the output:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Found that we need to send a handshake message right after the connection is established

var payload = JSON.stringify({
  'protocol': 'json',
  'version': 1
});

but with Record Ending char (ASCII char 30) at the end.

So I ended up sending:

const endOfRecord = String.fromCharCode(30);

var payload = JSON.stringify({
  'protocol': 'json',
  'version': 1
}) + endOfRecord;

After that everything started working properly.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda