Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

kurento-client always crashes on node.js >=6.3 (dependency bug) #116

Closed
bschmitlin opened this issue Aug 19, 2016 · 15 comments · May be fixed by KurentoForks/reconnect-ws#1 or Kurento/kurento-jsonrpc-js#1
Assignees
Labels
enhancement Potential improvement or feature request js-api

Comments

@bschmitlin
Copy link

using node 6.4 with [email protected] connected to latest master branch kurento-server.

Due to (from my understanding) an incompatibility of the ws library with node.js 6.3, when opening the websocket kurento-client crashes the node app:

2016-08-19T09:13:32.432Z - error: RangeError: out of range index
at RangeError (native)
at fastCopy (/Users/benoit/git/rtc/node_modules/ws/lib/Receiver.js:317:24)
at Receiver.add (/Users/benoit/git/rtc/node_modules/ws/lib/Receiver.js:78:3)
at Socket.firstHandler (/Users/benoit/git/rtc/node_modules/ws/lib/WebSocket.js:663:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:177:18)
at Socket.Readable.push (_stream_readable.js:135:10)
at TCP.onread (net.js:542:20)

seems to be websockets/ws#778
which would affect [email protected] used by kurento-client. This bug is apparently fixed in [email protected].

@bschmitlin bschmitlin changed the title kurento-client always crashes on node.js >6.3 (ws dependency bug?) kurento-client always crashes on node.js >=6.3 (dependency bug) Aug 30, 2016
@bschmitlin
Copy link
Author

@igracia @gortazar @rbenitez
Hi guys, any triage on this? AFAIK this basically blocks Kurento being usable on any recent nodejs deployments. Of course it would be great to also take this opportunity to update the super old ws lib version (over 2 years old) for some nice security and perf fixes.
Thanks!

@lotas
Copy link

lotas commented Sep 6, 2016

I +1 this, as I also experience problems right now, after upgrading to latest node.js.
My setup:

$node -v
v6.5.0
$kurento-media-server -v
Version: 6.5.0
Found modules:
        Module: 'core' version '6.5.0'
        Module: 'elements' version '6.5.0'
        Module: 'filters' version '6.5.0'

$npm list
...
├─┬ [email protected]
...
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └─┬ [email protected]
│ │ │ │   └── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └─┬ [email protected]
│ │ │ │   └── [email protected]
│ │ │ ├── [email protected]
│ │ │ └─┬ [email protected]
│ │ │   ├── [email protected]
│ │ │   └── [email protected]
│ │ └─┬ [email protected]
│ │   ├── [email protected]
│ │   ├── [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected] (git://github.com/kurentoforks/reconnect-ws.git#7fb7020e3ca1ffeaaa8bb4ddd690cf28c8d02a2b)
│   ├─┬ [email protected] (git://github.com/kurentoforks/reconnect-core.git#921d43e91578abb2fb2613f585c010c1939cf734)
│   │ └── [email protected]
│   └─┬ [email protected]
│     ├── [email protected]
│     └── [email protected]

And I get this error:

RangeError: out of range index
    at RangeError (native)
    at fastCopy (/home/codeship-kms-app-server/kms-app-server/source/node_modules/websocket-stream/node_modules/ws/lib/Receiver.js:317:24)
    at Receiver.add (/home/codeship-kms-app-server/kms-app-server/source/node_modules/websocket-stream/node_modules/ws/lib/Receiver.js:78:3)
    at Socket.firstHandler (/home/codeship-kms-app-server/kms-app-server/source/node_modules/websocket-stream/node_modules/ws/lib/WebSocket.js:663:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:543:20)

Which leads to the same [email protected] fix.
thanks!

@haggholm
Copy link

I hate to say +1, but…+1.

  • kurento-client depends on kurento-jsonrpc, which depends on ws@~0.4.31.
  • Also, kurento-client depends on KurentoForks/reconnect-ws, which depends on ws@~0.4.31 through websocket-stream@~0.5.1.

websocket-stream@~0.5.1 is at least two years old—it hit 1.1.1 in November 2014. ws@~0.4.31 is also two years old; it hit 0.5.0 in November 2014. So, two dependencies are two years out of date.

I’m not sure how to fix this. The naïve approach of forking the repositories and updating the dependency does not work, which isn’t surprising (I’m sure many APIs may have changed). This gives me the rather bizarre error message

TypeError: Invalid JsonRPC version 'undefined': {"id":0,"jsonrpc":"2.0","result":{"value":"pong"}}
at Object.unpack (...snip.../node_modules/kurento-jsonrpc/lib/packers/JsonRPC.js:74:11)

@igracia
Copy link
Contributor

igracia commented Oct 3, 2016

We'd really like to update those deps too. The thing is that we can't estimate how long it would take us to fix things for the new versions, and since it's working in the LTS version of node.js, we haven't scheduled that yet.

@igracia igracia added enhancement Potential improvement or feature request js-api labels Oct 3, 2016
@igracia igracia self-assigned this Oct 3, 2016
@bschmitlin
Copy link
Author

Great to see the bug being assigned :-D.

it's working in the LTS version of node.js
Just in case you hadn't notice, it looks like you have 14 days left to complete the work for your statement to remain true... https://github.com/nodejs/LTS#lts_schedule

For the reconnect feature perhaps it would be worth looking at what engine.io (socket.io engine) is doing?
Btw, it would be nice if the console.log('reconnect to server') from kurento-client that are cluttering our production logs could go away as part of this modernisation work.

Thanks and good luck!

@igracia
Copy link
Contributor

igracia commented Oct 5, 2016

@bschmitlin yeah, we postponed this for too long, sorry! First we are going to try and update the forks, so it stops pestering devs using node >6.3. After that, we'll try and go for something like what you pointed or maybe reconnecting-websocket

Will try and make the log more configurable, probably using winston or loglevel

@igracia
Copy link
Contributor

igracia commented Oct 5, 2016

@bschmitlin We've submitted a patch that should fix this for now, until we move to a more stable ws with reconnection library. Had to update the reference to ws in the KurentoForks/reconnect-ws library, and tested some other things apart from that to see if we could use the latest code from reconnect-core too. Can you please check that this patch does indeed solves the issue?

@bschmitlin
Copy link
Author

@igracia Thanks for the super quick patch. It works fine on node 6.7.0 in the somewhat limited testing I've done.

@igracia
Copy link
Contributor

igracia commented Oct 6, 2016

@bschmitlin Thanks for the feedback. It works also in all the other tests that we have. It seems like we can close this issue then.

Haven't done anything about logging yet, sorry! Will tackle that later on, as we have more pressing matters right now. Sorry it's bothering you, you'll have to put up with that a little longer ;-)

@igracia igracia closed this as completed Oct 6, 2016
@superdump
Copy link

The version of websocket-stream used depends on ws 0.4.32 and triggers this issue.

@igracia
Copy link
Contributor

igracia commented Nov 18, 2016

@superdump In which version of node? Can you be a bit more specific with the report?

@superdump
Copy link

superdump commented Nov 18, 2016

v6.9.1

I am using "kurento-client": "Kurento/kurento-client-js" in package.json and observing:

/app/node_modules/websocket-stream/node_modules/ws/lib/Receiver.js:317
    default: srcBuffer.copy(dstBuffer, dstOffset, 0, length); break;
                       ^

RangeError: out of range index
    at RangeError (native)
    at fastCopy (/app/node_modules/websocket-stream/node_modules/ws/lib/Receiver.js:317:24)
    at Receiver.add (/app/node_modules/websocket-stream/node_modules/ws/lib/Receiver.js:78:3)
    at Socket.firstHandler (/app/node_modules/websocket-stream/node_modules/ws/lib/WebSocket.js:663:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)

This happens very regularly. A bit of googling lead me here and I checked the ws version that is pulled in by websocket-stream and it has "ws": "~0.4.30" in its package.json so I suspect it is the same issue there. More specifically it is pulling in 0.4.32 as I noted in my last comment.

@superdump
Copy link

That is with KMS 6.6.1 and nightlies.

@peffis
Copy link

peffis commented Nov 19, 2016

@haggholm The error you see when upgrading are from these lines in kurento-jsonrpc-js: https://github.com/Kurento/kurento-jsonrpc-js/blob/master/lib/packers/JsonRPC.js#L63-L75

The reason is that when you bump the version of websocket-stream to something more modern (my testing indicates that the breaking change occurs when you go over 1.*) the unpack is no longer being called with a String but with an object. This object however can easily be made into a string (which is what is happening in the error printout later in the above code - when it is doing the "+ message") so the obvious patch is to introduce an extra toString when the message is not a String:

result = JSON.parse(message.toString());

This seems to, with very limited testing, make the kurento client work also with latest websocket-stream. At least it does not stop on that error and the traffic seems to go through.

@progre
Copy link

progre commented Mar 31, 2017

I created PR for fix it.
Please check those.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Potential improvement or feature request js-api
Projects
None yet
7 participants