k6 community forum

Websocket: close 1006 error

Dear K6 experts,

I use 40 websocket sessions during my performance test, sometimes I encounter “websocket: close 1006 error”, according to “https://stackoverflow.com/questions/54101923/1006-connection-closed-abnormally-error-with-python-3-7-websockets”, this kind of issue seems to be websocket client related, but I am not sure. Pls feel free to let me know if you need additional info.

Error message:
INFO[0002] connected
INFO[0535] An unexpected error occured: 0=“websocket: close 1006 (abnormal closure): unexpected EOF”
INFO[0535] disconnected

K6 script:

var url = "wss://xxxx"
        var params = {};
        var response = ws.connect(url, params, function (socket) {

            socket.on('open', function () {
                console.log('connected');
            });

            socket.on('message', function (data) {
                
            });

            socket.on('close', function () {
                console.log('disconnected');
            });

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

            socket.setTimeout(function () {
                console.log(duration + ' seconds passed, closing the socket');
                socket.close();
            }, duration * 1000);


        });

my k6 version is “k6 v0.26.0".

Thanks,
Roy

Hi @royzhang007,

Given this discussion of the implementation, we are using, I would guess that the server sends a smaller message then what it says it would do. Or we do the same, but this seems unlikely, especially given that I don’t see any calls to socket.send :).

Are you certain that underload your application doesn’t start misbehaving? Or maybe something in the way (firewall, VPN, proxy) has some kind of limit?

Thx @mstoykov!
" Or we do the same, but this seems unlikely, especially given that I don’t see any calls to socket.send :)."

Do u mean if there is no message from websocket server, websocket client(k6) will throw out 1006 error?

Thanks,
Roy

No, @royzhang007, k6 won’t throw a 1006 because the server doesn’t write a message.

Your current error is very certainly because the server you are testing didn’t write enough data at one point or another. I based this on the fact that the error is unexpected EOF which usually means that k6 expected to read something more but … there was nothing to read. I can only imagine two things:

  1. During the connection, something happens and we don’t actually connect at all and the other side closes the connection … for example because we are doing more connections then it is configured to handle.
  2. The server closes the connection without sending us a “close” message.

I would recommend looking in your WebSocket server implementation and if it something that you write to think about if it won’t misbehave in the above ways. Also, anything in between k6 and the WS server could interfere and implement some kind of throttling.
Try running with less and more WebSocket sessions and if it disappears with less but is more prominent with more it is very likely your implementation/setup can’t handle the load or is misconfigured(or both:))