k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Websockets should tag connection errors better

Open mstoykov opened this issue 4 years ago • 5 comments

Currently, if an error (like timeout) happens during the creation of the websocket k6 will not emit status=0 or tags error and error_code as will the HTTP module, but will just no emit the status tag, call the error handle if defined and end continue executing javascript.

This will require for the error_code code to be made exported and possibly moved to a different module, which will impact #2008, so we might want to merge that first.

mstoykov avatar May 14 '21 13:05 mstoykov

@neha13rb1998, you can define an error handler, see https://k6.io/docs/javascript-api/k6-ws/socket/socket-on-event-callback

na-- avatar Jul 09 '21 11:07 na--

@neha13rb1998, you can define a new custom metric (e.g. a Counter) and add() to it in the error websocket handler, see:

  • https://k6.io/docs/using-k6/metrics/#custom-metrics
  • https://k6.io/docs/javascript-api/k6-metrics/counter/

na-- avatar Jul 12 '21 14:07 na--

@neha13rb1998, move the errorCounter.add(1); in the body of the socket.on('error', function(e){ ... } function, like this:

    socket.on('error', function(e){
        if (e.error() != 'websocket: close sent') {
            errorCounter.add(1);
            console.log('An unexpected error occured: ', e.error());
        }
    });

Also, please don't use this github issue for support, use the community forum instead: https://community.k6.io/ (see these instructions).

na-- avatar Jul 13 '21 06:07 na--

#$qwerty

ghost avatar Sep 28 '21 16:09 ghost

#$qwerty

qwertyu

neha13rb1998 avatar Sep 28 '21 16:09 neha13rb1998

A new experimental WebSocket module exists and we aim to graduate it as stable. So, I'm closing this in favor of its clone on the new module https://github.com/grafana/xk6-websockets/issues/8.

codebien avatar May 22 '24 11:05 codebien