websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.79k stars 2.44k forks source link

Ws._receiver._state: 0 #2113

Closed flav-code closed 1 year ago

flav-code commented 1 year ago

Is there an existing issue for this?

Description

From time to time I don't know why but when this state goes to 4 then I don't receive the events anymore and when the problem happens I have no error

ws version

8.12.0

Node.js Version

v18.13.0

System

image

Expected result

The state must be equal to 0 to works fine

Actual result

Some times the state is 4 and never back to 0

Attachments

No response

lpinca commented 1 year ago

Are you using the "permessage-deflate" extension? Do you have a reproducible test case? Are you sure that the other peer is still responsive and still sends data?

The parser state 4 means "waiting for data from the other peer".

flav-code commented 1 year ago

I can't reproduce the bug

flav-code commented 1 year ago

I think something is going on and it's stuck on state 4 I would like to point out that I can still send messages, but in any case I receive them more

lpinca commented 1 year ago

I think the other peer just stops sending data. Without a way to reproduce the issue there is not much I can do.

flav-code commented 1 year ago

they send well but I think the problem is the customer

lpinca commented 1 year ago

The only way to get stuck on state 4 is this https://github.com/websockets/ws/blob/8.12.0/lib/receiver.js#L427, so I guess data is no longer read/flowing. I have not idea why.

flav-code commented 1 year ago

I will check if _loop is equal to false

flav-code commented 1 year ago

I just had the bug again and I see that the _loop property remains locked at true image

lpinca commented 1 year ago

How and when are you logging that? Please provide more details, otherwise it is not really useful. If it is truly stuck in an endless loop, your app would be completely blocked with 100% CPU usage.

flav-code commented 1 year ago

I have a discord bot and i use a librairie https://github.com/Deivu/Shoukaku to connect to a lavalink server to play music. The author is @Deivu Ws._receiver

I have no particular option

image

The cpu process is not 100%.

lpinca commented 1 year ago

The cpu process is not 100%.

Then it is not stuck in an endless loop.

When issue occurs check

  1. If the raw socket is paused.
  2. If the above is false, if new data is read from the raw socket.
    websocket._socket.prependListener('data', function (chunk) {
      console.log(chunk.toString('hex'));
    });
flav-code commented 1 year ago

I found the data from yesterday, I will add the listener as soon as the problem returns The socket is not paused

image image

flav-code commented 1 year ago

I added the listener and I get good data

lpinca commented 1 year ago

Show the data so we have a way to reproduce the issue.

flav-code commented 1 year ago

I am constantly receiving data so I can't tell which one is causing the problem. The socket doesn't even send me an error.

lpinca commented 1 year ago

If you can share the data, save it in a file, then when issue occurs post the file here. Use all the data, from the moment the WebSocket is created to the moment the issue occurs.

lpinca commented 1 year ago

@flav28 when you write to the file use something to separate each chunk of data. For example, if you use the hex form as in the example above, then keep the new line between each chunk.

flav-code commented 1 year ago

Yes, so that you can distinguish the elements and test them one by one. I can make you an array or a txt

flav-code commented 1 year ago

I made a system where I keep the last 10 000 events, I push the chunk in hex in an array and I am warned in the 5s after the incident and I make a command and it generates me a json with an array of chunck

lpinca commented 1 year ago

I made a system where I keep the last 10 000 events

The problem with this is that the first element might be a frame without its head. Is it possible to keep everything from the beginning? It's ok if it is a plain txt. Having an array would be convenient but it is not necessary. It can be done later.

flav-code commented 1 year ago

actually in my case it's in production the services are already restarting, and I'm convinced that when the problem happens it's because of a corrupted packet or something like that. I can increase the size but I don't want it to impact the system

lpinca commented 1 year ago

I don't know your requirements but writing to a file should be acceptable for some time if you have enough space.

flav-code commented 1 year ago

well as I said it pushes in an array in ram and as soon as the problem arises I make a command and it will create the file .json with an array of chunck

lpinca commented 1 year ago

Any update?

lpinca commented 1 year ago

I'm closing this due to inactivity.