Skip to content

Android RuntimeException thrown by WebSocketModule in send #16214

@ivorcho

Description

@ivorcho

Hello,

We are experiencing a rare and hard to reproduce crash on Android devices caused by RuntimeException thrown by com.facebook.react.modules.websocket.WebSocketModule in send() method. We have difficulties to reproduce this error, but we are getting reports about it happening in Play Store. Here is the full stack trace:

java.lang.RuntimeException: Cannot send a message. Unknown WebSocket id 7 at com.facebook.react.modules.websocket.WebSocketModule.send(WebSocketModule.java:226) at java.lang.reflect.Method.invoke(Method.java) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:363) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162) at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:154) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:762)

We are using "socket.io-client": "2.0.1" for socket connection and "react-native": "0.48.4".

From the source code I see this is happening when there is no such WebSocket client in the array of sockets. But what could lead to that? Maybe there is something wrong on how JS socket.io connections are handled by the native code. The comment is pointing it's a programmer error :D

public void send(String message, int id) { WebSocket client = mWebSocketConnections.get(id); if (client == null) { // This is a programmer error throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id); } try { client.send(message); } catch (Exception e) { notifyWebSocketFailed(id, e.getMessage()); } }
I see others have experienced this error as well, but because of the crash being sporadic and difficult to reproduce all issues have been closed :(.

Any kind of help will be appreciated. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions