Skip to content

WebSocket onmessage error with wasm64 #21515

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

Closed
tbuchs opened this issue Mar 12, 2024 · 4 comments · Fixed by #21527
Closed

WebSocket onmessage error with wasm64 #21515

tbuchs opened this issue Mar 12, 2024 · 4 comments · Fixed by #21527

Comments

@tbuchs
Copy link

tbuchs commented Mar 12, 2024

Hi, as already explained in #21503 im currently trying to work with -sMEMORY64. The previous bug is resolved, thank you for that. However, now if I receive a message I have the weird bug, that there is no data even though the debug message prints the data.
I have the following code to test:

static EM_BOOL WebSocketMessage([[maybe_unused]]int eventType, const EmscriptenWebSocketMessageEvent *e, void *userData) {
  cerr << "Received message" << endl;
  if(!e)
    cerr << "e is null" << endl;
  cerr << "e is not null";
  cerr << " " << e->numBytes;
  cerr << " " << e->isText;
  cerr << " " << e->socket;
  cerr << " " << e->data;
  string message = (char*)e->data;

The Debug Output is the following:

w:0,t:0x001782f0: websocket event "open": socketId=1,userData=1720968,callbackFunc=2620)
w:0,t:0x001782f0: emscripten_websocket_send_utf8_text(socketId=1,textData=42 ' chars, "{"conten...") 
w:0,t:0x001782f0: WebSocket onmessage, received data: "{"type":"login","success":true}", 31 chars, 32 bytes encoded as UTF-8: "{"type":"login","success":true}"
Received message
e is not null 0 0 1
Uncaught RuntimeError: index out of bounds

I get that the index is out of bounds, because there is no data - however the debug message prints the received message correctly? Thanks for your help!

sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 14, 2024
Update `test_websocket_send.c` such that it checks that both text
and binary messages are received.

Also, delete `websocket.c` which I think was supposed to be removed
as part of emscripten-core#7672 (where it was renamed to test_websocket_send.c).

Fixes: emscripten-core#21515
sbc100 added a commit that referenced this issue Mar 14, 2024
Update `test_websocket_send.c` such that it checks that both text
and binary messages are received.

Also, delete `websocket.c` which I think was supposed to be removed
as part of #7672 (where it was renamed to test_websocket_send.c).

Fixes: #21515
@tbuchs
Copy link
Author

tbuchs commented Jun 22, 2024

Is it possible, that the fix does not work anymore? I had a look in the library_websocket.js file and saw that some changes were made. If I remove does added lines before getSocketEvent, it works for me again.

Like this:

var LibraryWebSocket = {
  $WS: {
    sockets: [null],
    socketEvent: null,
    getSocketEvent(socketId) {
      // Singleton event pointer.  Use EmscriptenWebSocketCloseEvent, which is
      // the largest event struct
      this.socketEvent ||= _malloc({{{ C_STRUCTS.EmscriptenWebSocketCloseEvent.__size__ }}});
      {{{ makeSetValue('this.socketEvent', 0, 'socketId', 'u32') }}};
      return this.socketEvent;
    },
  },
  emscripten_websocket_get_ready_state__deps: ['$WS'],

@sbc100
Copy link
Collaborator

sbc100 commented Jun 22, 2024

What error are you seeing now?

Are you referring to the changed made in #21531? Did you remove the new getSocket helper along with all the callers of that function?

@sbc100
Copy link
Collaborator

sbc100 commented Jun 22, 2024

Maybe open a new bug? Unless you think the new issue is is the same thing (i.e. wasm64 related).

@tbuchs
Copy link
Author

tbuchs commented Jun 23, 2024

Are you referring to the changed made in #21531? Did you remove the new getSocket helper along with all the callers of that function?

Yes, at least that's what I thought. I only removed the getSocket call in the first place. However, i tried to revert my changes and installed/activated the latest Emscripten version (3.1.61) again and somehow the error changed and I can't submit you any details. Please just ignore it - thanks for your help.

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

Successfully merging a pull request may close this issue.

2 participants