react-native icon indicating copy to clipboard operation
react-native copied to clipboard

WebSocket.js doesn't update readyState in case of 'websocketFailed' event

Open tepamid opened this issue 10 years ago • 4 comments

Hello!

We are building a react-native based application which extensively uses WebSockets. The Android app crashes right after waking up being in suspended mode for a coupe of days and throws an exception:

"Cannot send a message. Unknown WebSocket id 1"

Before calling WebSocket.send(...) method from WebSocket.js we always check its readyState. I believe the problem is caused by not updating readyState if case of 'websocketFailed' event. this.close() cause the current used websocket ID to be removed from mWebSocketConnections HashMap (WebSocketModule.java), but readyState stays the same.

  this._eventEmitter.addListener('websocketFailed', ev => {
    if (ev.id !== this._socketId) {
      return;
    }
    this.dispatchEvent(new WebSocketEvent('error', {
      message: ev.message,
    }));
    this.dispatchEvent(new WebSocketEvent('close', {
      message: ev.message,
    }));
    this._unregisterEvents();
    this.close();
  })

I think readyState must be updated similarly to the 'websocketClosed' event case:

  this._eventEmitter.addListener('websocketClosed', ev => {
    if (ev.id !== this._socketId) {
      return;
    }
    this.readyState = this.CLOSED;
    this.dispatchEvent(new WebSocketEvent('close', {
      code: ev.code,
      reason: ev.reason,
    }));
    this._unregisterEvents();
    this.close();
  }),

React-native 0.31.0 Android 6.0

tepamid avatar Aug 18 '16 09:08 tepamid

@facebook-github-bot label Icebox

charpeni avatar Nov 14 '16 02:11 charpeni

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/websocketjs-doesnt-update-readystate-in-case-of-websocketfailed-event

ProductPains helps the community prioritize the most important issues thanks to its voting feature. It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix. We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

charpeni avatar Nov 14 '16 02:11 charpeni

@facebook-github-bot close

charpeni avatar Nov 14 '16 02:11 charpeni

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

facebook-github-bot avatar Nov 14 '16 02:11 facebook-github-bot