Skip to content

Commit

Permalink
Fix IllegalStateException crash in WebSocketModule.java
Browse files Browse the repository at this point in the history
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 #6301

Differential Revision: D3016099

fb-gh-sync-id: 838dd9d2e5e5b7a4e2242fa6de5658dfdaf24f55
shipit-source-id: 838dd9d2e5e5b7a4e2242fa6de5658dfdaf24f55
  • Loading branch information
Kevin Stumpf authored and Facebook Github Bot 6 committed Mar 5, 2016
1 parent 970782d commit a6a89fe
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -176,7 +177,7 @@ public void send(String message, int id) {
client.sendMessage(
WebSocket.PayloadType.TEXT,
new Buffer().writeUtf8(message));
} catch (IOException e) {
} catch (IOException | IllegalStateException e) {
notifyWebSocketFailed(id, e.getMessage());
}
}
Expand Down

0 comments on commit a6a89fe

Please sign in to comment.