Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket connection does not respect the throw option #2247

Closed
na-- opened this issue Nov 18, 2021 · 1 comment
Closed

WebSocket connection does not respect the throw option #2247

na-- opened this issue Nov 18, 2021 · 1 comment
Labels
breaking change for PRs that need to be mentioned in the breaking changes section of the release notes bug
Milestone

Comments

@na--
Copy link
Member

na-- commented Nov 18, 2021

k6 version

all

OS

all

Docker version and image

No response

Expected Behaviour

With this code:

import ws from 'k6/ws';

export let options = {
    throw: false,
};

export default function () {
    try {
        const resp = ws.connect('wss://test-api.k6.io/whatever-non-ws-url', null, function (socket) {
            socket.on('open', function () {
                console.log('connected');
                socket.close();
            });

            socket.on('error', function (e) {
                console.error('connection error occurred: ', e.error());
            });

            socket.on('close', function () {
                console.log('disconnected');
            });
        });
        console.log(`ended normally, response: \n${JSON.stringify(resp, null, 4)}`);
    }
    catch (e) {
        console.error(`ended with exception, error: ${e}`);
    }
}

I expect the ws.connect() call to return normally and emit a warning log message, and the Response to contain an appropriate error and error code. This is what happens with HTTP requests (which the websocket starts with) when throw is false.

Related issue: #2024

Actual Behaviour

An exception will be thrown and ended with exception, error: websocket: bad handshake logged.

Steps to Reproduce the Problem

Run the code above.

@na-- na-- added the bug label Nov 18, 2021
@na-- na-- changed the title [Bug]: websocket connection does not respect the throw option WebSocket connection does not respect the throw option Nov 22, 2021
@mstoykov mstoykov added the breaking change for PRs that need to be mentioned in the breaking changes section of the release notes label Aug 31, 2022
@na-- na-- added this to the v0.40.0 milestone Sep 13, 2022
@na--
Copy link
Member Author

na-- commented Sep 13, 2022

This was fixed by #2616

@na-- na-- closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change for PRs that need to be mentioned in the breaking changes section of the release notes bug
Projects
None yet
Development

No branches or pull requests

2 participants