mojolicious / mojo

:sparkles: Mojolicious - Perl real-time web framework

Home Page:https://mojolicious.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Websocket messages containing arbitrary bytes never reach the server.

sergiotarxz opened this issue · comments

  • Mojolicious version: 9.31
  • Perl version: 5.36.0
  • Operating system: Gentoo GNU/Linux

Steps to reproduce the behavior

Websocket messages containing arbitrary bytes never reach the server.

I have setup two git repos https://git.owlcode.tech/sergiotarxz/msgba-web, https://git.owlcode.tech/sergiotarxz/msgba.

The web should work as a proxy for websockets implemented over unix domain sockets for the plain msgba project.

But when I do the following

                const packet_u8 = concatU8Array( 
                    concatU8Array(u64ToByteArrayBigEndian(id), u64ToByteArrayBigEndian(BigInt(raw_data.length))),
                    raw_data
                );
                const packet_blob = packet_u8.buffer;
                console.log('Sending packet');
                websocket.send(packet_blob);

The perl code:

   sub handle {
        my $self = shift;
        my $ws = $self->ws;
        $self->_build_msgba_connection;
        $ws->on('binary', sub {
            my ($ws, $bytes) = @_;
            if (!$bytes) {
                warn "Received empty message";
                return;
            }     
            say "Received message";
            say unpack 'H*', $bytes;
            open my $fh, '<', \$bytes;
            read $fh, my $id, 8;
            read $fh, my $size, 8;
            $size = unpack 'Q>', $size;
            close $fh;
            $self->msgba_connection->print($bytes);
        });
        return;
        #while (my $packet = $self->read_packet) {
        #    $self->handle_packet($packet);
        #}
        #close $self->msgba_connection;
        #$ws->closed;
    }

Expected behavior

I get in $bytes of msgba-web the message from websockets.

Actual behavior

Never receives the packet, sometimes it will print a message like

n!�e��dt(7� header at /home/sergio/perl5/lib/perl5/Mojo/Content.pm line 247.�e���%n�g��n�D&#�Lg���faaadc��{i5gdc�0*Q�4N�g���#��ܒ��(fm�5'�\%'�TJL��JL��eL��݁����Yfdc�`dc�f�;�[L��g�W�fAټuA�

Apparently the allowed message size was too small, it appears solved after tuning it, I was getting 1009 websocket errors.

It remains unexplained the header message.