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

TypeError: Cannot read property 'binary' of undefined #5971

Closed
solenum opened this issue Dec 22, 2017 · 4 comments · Fixed by #16720
Closed

TypeError: Cannot read property 'binary' of undefined #5971

solenum opened this issue Dec 22, 2017 · 4 comments · Fixed by #16720
Labels

Comments

@solenum
Copy link

solenum commented Dec 22, 2017

I'm writing some networking code using sdl_net and I'm getting this error & crash (on the server) any time I send data from the client to the server (but not the other way around).

TypeError: Cannot read property 'binary' of undefined
    at WebSocket.<anonymous> (/home/exezin/Projects/zambies/src/build/server/server.js:1:205170)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at Receiver._receiver.onmessage (/home/exezin/node_modules/ws/lib/WebSocket.js:141:47)
    at Receiver.dataMessage (/home/exezin/node_modules/ws/lib/Receiver.js:380:14)
    at Receiver.getData (/home/exezin/node_modules/ws/lib/Receiver.js:330:12)
    at Receiver.startLoop (/home/exezin/node_modules/ws/lib/Receiver.js:165:16)
    at Receiver.add (/home/exezin/node_modules/ws/lib/Receiver.js:139:10)
    at Socket._ultron.on (/home/exezin/node_modules/ws/lib/WebSocket.js:138:22)

Commenting out the following 'if (!flags.binary)' statement in the server.js output results in a functioning server and everything works as expected.

if (ENVIRONMENT_IS_NODE) {
  peer.socket.on('open', handleOpen);
  peer.socket.on('message', function(data, flags) {
    if (!flags.binary) {
      return;
    }
    handleMessage((new Uint8Array(data)).buffer);  // copy from node Buffer -> ArrayBuffer
  });

What's even more strange is I've written a minimal test case and this doesn't crop up on that, it's only happening when trying to integrate it into my larger project, which uses various other libraries. (here are the flags)

-O2 -s USE_WEBGL2=1 -s USE_GLFW=3 -s USE_FREETYPE=1 -s ALLOW_MEMORY_GROWTH=1 -s USE_SDL_NET=2

(Server run via node, client run via js/html output. All on localhost)

Looking at the latest websocket, is it possible that flags was deprecated?

@solenum
Copy link
Author

solenum commented Dec 22, 2017

Reverting to an older version of websockets in npm/node fixes the issue. It looks like flags was removed in the latest websocket and thus causes this issue? Seems emscripten/the sdl_net port needs to be updated to represent this?

See here: websockets/ws@c15118f

@ternaam
Copy link

ternaam commented Oct 9, 2018

Right now I have to revert to version 2 of 'ws'. (out of 6 major versions that exist). Using version 2 also triggers a npm vulnerability warning for the 'ws' package.

Is there a workaround I'm not aware of? (That doesn't involve patching emscripten?)

@lcgamboa
Copy link

lcgamboa commented Nov 8, 2018

Apparently the version of ws used in the emscripten socket tests is 0.8.0 (in the directory tests/sockets/ws ). And it really only supports at most version 2 of ws. Versions of ws greater than 2 cause the tests to fail. To correct this problem is possibly only updating the code emscripten.

@stale
Copy link

stale bot commented Jan 26, 2020

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

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

Successfully merging a pull request may close this issue.

3 participants