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

Error decoding fragmented frames #70

Open
jeanparpaillon opened this issue Sep 2, 2021 · 0 comments
Open

Error decoding fragmented frames #70

jeanparpaillon opened this issue Sep 2, 2021 · 0 comments

Comments

@jeanparpaillon
Copy link

NodeJS websocket server

var server = require('websocket').server;

var http = require('http');

var app = http.createServer();

app.listen(8080, function() {
    console.log('running on port 8080');
});

var ws = new server({
    httpServer: app,
    autoAcceptConnections: false,
    keepalive: false,
    disableNagleAlgorithm: false
});

ws.on('request', function(req) {
    if (req.httpRequest.url.indexOf('/0/session/') === 0) {
        console.log('new request');
        var connection = req.accept('ws', req.origin);

        connection.on('message', function(message) {

            if (message.type === 'utf8') {
                /* Receive integer, send as may bytes as JSON */
                var bytes = Number(message.utf8Data);

                if (!Number.isNaN(bytes)) {
                    console.log('sending ' + bytes + ' bytes of data');

                    connection.send(new Array(bytes + 1).join('.'));
                }
            }
        });
    }
});

When asked for + tenth kB (to be defined), client crashes with:

** (FunctionClauseError) no function clause matching in :websocket_client.disconnected/3
    (websocket_client 1.4.2) /home/jean/ws_cli_test/deps/websocket_client/src/websocket_client.erl:291: :websocket_client.disconnected(:cast, :connect, {:context, {:websocket_req, :ws, 'localhost', 8080, '/0/session/', 5000, #Reference<0.1445969634.340525062.178319>, 1, #Port<0.10>, {:transport, :gen_tcp, :tcp, :tcp_closed, :tcp_error, [mode: :binary, active: true, packet: 0]}, "zkOLuxAroVzrOKg721ev0Q==", :undefined, 1, :undefined, :undefined, :undefined}, {:transport, :gen_tcp, :tcp, :tcp_closed, :tcp_error, [mode: :binary, active: true, packet: 0]}, [{"Sec-WebSocket-Protocol", "ws"}], {:ws, 'localhost', 8080, '/0/session/'}, {WsCliTest.Socket, %{}}, "", false, 0})
    (stdlib 3.15.2) gen_statem.erl:1194: :gen_statem.loop_state_callback/11
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Initial Call: :websocket_client.init/1
Ancestors: [#PID<0.230.0>, #PID<0.229.0>]
Message Queue Length: 0
Messages: []
Links: [#PID<0.230.0>]
Dictionary: []
Trapping Exits: false
Status: :running
Heap Size: 1598
Stack Size: 29
Reductions: 8702

jeanparpaillon pushed a commit to jeanparpaillon/websocket_client that referenced this issue Sep 3, 2021
When receiving fragmented frames, decoding can fail if websocket / TCP
fragmentation is aligned for the last frame.

Fixes sanmiguel#70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant