Skip to content

experimental/websockets: WebSocket.send(TypedArray) sends the entire underlying buffer #5226

@dop251

Description

@dop251

Brief summary

WebSocket.send() should not send the entire underlying ArrayBuffer for type arrays or DataView.

k6 version

1.3.0

OS

Linux

Docker version and image (if applicable)

No response

Steps to reproduce the problem

export default async function() {
    const ws = new WebSocket(`wss://echo.websocket.org`);
    ws.binaryType = 'arraybuffer';
    ws.addEventListener('open', (event) => {
        const a = new Uint8Array(1024);
        ws.send(a.subarray(0, 1));
    });

    ws.addEventListener('close', (event) => {
        console.log('Closed', event);
    })
    return new Promise(resolve => {
        ws.addEventListener('message', (event) => {
            if (event.data instanceof ArrayBuffer) {
                console.log("Length", event.data.byteLength);
                ws.close();
                resolve(undefined);
            }
        });
    })
}

Expected behaviour

Should print:

Length 1

Actual behaviour

Prints:

Length 1024

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions