Skip to content

WebSocket onmessage error with wasm64 #21515

Closed

Description

@tbuchs

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!

Activity

  1. added a commit that references this issue on Mar 14, 2024
    30bb30b
  2. added a commit that references this issue on Mar 14, 2024
    46917a5
  3. tbuchs commented on Jun 22, 2024

    @tbuchs
    Author

    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'],
    
  4. sbc100 commented on Jun 22, 2024

    @sbc100
    Collaborator

    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?

  5. sbc100 commented on Jun 22, 2024

    @sbc100
    Collaborator

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

  6. tbuchs commented on Jun 23, 2024

    @tbuchs
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions