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

invalid payload error on socket_error event #4830

Open
MuhammedAlmaz opened this issue Sep 19, 2023 · 3 comments
Open

invalid payload error on socket_error event #4830

MuhammedAlmaz opened this issue Sep 19, 2023 · 3 comments

Comments

@MuhammedAlmaz
Copy link

Describe the bug
I am trying to implementation android and nodejs server. When i am connect to server from android device i am getting invalid payload after 5-6 sec. I tried many things. I've checked #4392 issue but there is not any solve way. I can see the first emit when i connect to server but after some sec later my connection closing.

This issue is not happening all clients. Only some of them about %10 of clients.

I have an apache server which is reverse proxying to my socket.

The config of apache server

<VirtualHost _default_:443>
        ServerName socket.xxxx.com
        SSLEngine On
        SSLCertificateFile /etc/ssl/socket/primary.crt
        SSLCertificateKeyFile /etc/ssl/socket/private.key
        SSLCertificateChainFile /etc/ssl/socket/intermediate.crt


        LoadModule authn_file_module            modules/mod_authn_file.so
        LoadModule authn_core_module            modules/mod_authn_core.so
        LoadModule authz_host_module            modules/mod_authz_host.so
        LoadModule authz_groupfile_module       modules/mod_authz_groupfile.so
        LoadModule authz_user_module            modules/mod_authz_user.so
        LoadModule authz_core_module            modules/mod_authz_core.so
        LoadModule headers_module               modules/mod_headers.so
        LoadModule lbmethod_byrequests_module   modules/mod_lbmethod_byrequests.so
        LoadModule proxy_module                 modules/mod_proxy.so
        LoadModule proxy_balancer_module        modules/mod_proxy_balancer.so
        LoadModule proxy_http_module            modules/mod_proxy_http.so
        LoadModule proxy_wstunnel_module        modules/mod_proxy_wstunnel.so
        LoadModule rewrite_module               modules/mod_rewrite.so
        LoadModule slotmem_shm_module           modules/mod_slotmem_shm.so
        
        SSLProxyEngine on
        SSLProxyVerify none
        Header set Access-Control-Allow-Origin "*"
        ProxyPass / http://localhost:9252/
        RewriteEngine on
        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteCond %{HTTP:Connection} upgrade [NC]
        RewriteRule ^/?(.*) "ws://localhost:9252/$1" [P,L]
        
        ProxyTimeout 30
    </VirtualHost>

Server side socket.io version is: "socket.io": "4.7.2"
Android side socket.io-client version is : implementation 'io.socket:socket.io-client:2.1.0'
Android Version: [8,9,10,11,12,13]

Server side codes

    socket.on('error', (error) => {
      console.log(`${moment().format('DD-MM-YYYY HH:mm:ss')} -> socket error ${socket.id} ${socket.handshake.query.connectionType} ${socket.room}`, error);
    });
    
    socket.on('disconnect', (reason, details) => {
      console.log(`Disconnected ${moment().format('DD-MM-YYYY HH:mm:ss')} -> ${socket?.room} - ${socket?.id} - ${reason} ${details}`);
    });

Error information

19-09-2023  20:50:25 -> socket error _rO9bl3lGaNKXIQ0AAAh 2 77 Error: invalid payload
    at Decoder.decodeString (/projects/prod_socket/node_modules/socket.io-parser/build/cjs/index.js:238:23)
    at Decoder.add (/projects/prod_socket/node_modules/socket.io-parser/build/cjs/index.js:141:27)
    at Client.ondata (/projects/prod_socket/node_modules/socket.io/dist/client.js:182:26)
    at Socket.emit (events.js:400:28)
    at Socket.onPacket (/projects/prod_socket/node_modules/engine.io/build/socket.js:122:22)
    at WebSocket.emit (events.js:400:28)
    at WebSocket.onPacket (/projects/prod_socket/node_modules/engine.io/build/transport.js:92:14)
    at WebSocket.onData (/projects/prod_socket/node_modules/engine.io/build/transport.js:101:14)
    at WebSocket.<anonymous> (/projects/prod_socket/node_modules/engine.io/build/transports/websocket.js:20:19)
    at WebSocket.emit (events.js:400:28)
    
    
    Disconnected 19-09-2023  20:50:28 -> 77 - _rO9bl3lGaNKXIQ0AAAh - forced close undefined
@MuhammedAlmaz MuhammedAlmaz added the to triage Waiting to be triaged by a member of the team label Sep 19, 2023
@MuhammedAlmaz
Copy link
Author

MuhammedAlmaz commented Sep 19, 2023

I tried to collect more information about bug.

And i find a thing. This event firing that error payload thing. I edited the server code and find an event.

The code line is : /projects/prod_socket/node_modules/socket.io-parser/build/cjs/index.js:238:23
image

and the console output is: null { type: 2, nsp: '/', id: 3186, data: null }

Data is null idk why there is null event but i find that. Maybe it will help to solve that issue.

Android connection code is;

            IO.Options opts = new IO.Options();
            opts.secure = true;
            opts.reconnectionDelay = 5000;
            opts.timeout = 6000;
            opts.transports = new String[]{WebSocket.NAME, Polling.NAME};
            opts.query = "token=" + token + "&&connectionType=2";
            webSocket = IO.socket(this.socketUri, opts);

It seems like ping, pong request but i am not sure...

@MuhammedAlmaz
Copy link
Author

I found the bug i am not sure is it from client library or server but the problem is happening from "Ack Callback".

        webSocket.emit("client.register-room", username, new Ack() {
            @Override
            public void call(Object... args) {
                isRegistered=true;
            }
        });

When i run this method server closing socket and firing invalid payload error.

It is really interesting. Did not anybody use ACK callback on Java Client?

@darrachequesne
Copy link
Member

Hi! Thanks a lot for all the details.

In the payload { type: 2, nsp: '/', id: 3186, data: null }, the data: null is indeed invalid (it should be an array).

Not sure how it could happen though.

@darrachequesne darrachequesne added needs investigation and removed to triage Waiting to be triaged by a member of the team labels Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants