mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 04:24:15 +00:00
Fix IllegalStateException crash in WebSocketModule.java
Summary:- Motivation: The WebSocket implementation on Android crashes the app when an attempt is made to write on a web socket that was closed due to a spotty connection. We found this issue by using Pusher, which is built on WebSockets. The following stack trace reveals that the WebSocketModule doesn't catch the case of a closed connection, when a consumer attempts to write: ```sh Fatal Exception: java.lang.IllegalStateException: closed at com.squareup.okhttp.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:109) at com.facebook.react.modules.websocket.WebSocketModule.send(WebSocketModule.java:176) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:249) at com.facebook.react.bridge.NativeModuleRegistry$ModuleDefinition.call(NativeModuleRegistry.java:158) at com.facebook.react.bridge.NativeModuleRegistry.call(NativeModuleReg Closes https://github.com/facebook/react-native/pull/6301 Differential Revision: D3016099 fb-gh-sync-id: 838dd9d2e5e5b7a4e2242fa6de5658dfdaf24f55 shipit-source-id: 838dd9d2e5e5b7a4e2242fa6de5658dfdaf24f55
This commit is contained in:
parent
970782d147
commit
a6a89fe4e0
@ -10,6 +10,7 @@
|
||||
package com.facebook.react.modules.websocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.IllegalStateException;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
@ -176,7 +177,7 @@ public class WebSocketModule extends ReactContextBaseJavaModule {
|
||||
client.sendMessage(
|
||||
WebSocket.PayloadType.TEXT,
|
||||
new Buffer().writeUtf8(message));
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | IllegalStateException e) {
|
||||
notifyWebSocketFailed(id, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user