pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

React-Native Possible unhandled Promise Rejection #85

Closed iamchathu closed 5 years ago

iamchathu commented 5 years ago

The server gets connection request but doesn't work after that and doesn't connect to the server. But when I turn on remote JS debugging it works perfectly.

 React Native Environment Info:
    System:
      OS: macOS 10.14
      CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
      Memory: 1.29 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.1 - /usr/local/bin/node
      Yarn: 1.10.1 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
      Android SDK:
        Build Tools: 21.1.2, 23.0.1, 24.0.1, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.1
        API Levels: 18, 21, 22, 23, 24, 25, 26, 27
    IDEs:
      Android Studio: 3.1 AI-173.4907809
      Xcode: 10.0/10A255 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.5.0 => 16.5.0
      react-native: ^0.57.2 => 0.57.2

"reconnecting-websocket": "^4.1.5"

Device Android 5.1.1

pladaria commented 5 years ago

Hi,

Thanks for reporting. Could you please try the following?

  1. update to latest version
  2. set debug: true to enable RWS debug messages

Hopefully we can get some more information about this issue

iamchathu commented 5 years ago

Hi,

  1. I upgraded to "reconnecting-websocket": "^4.1.6"
  2. Set debug: true in options

Still, the problem exists. My WebSocket server receives the connection.

When I enable Debug JS remotely it works.

Currently, the only warning I have in the app is

Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object( evaluating '_d[0]')
_addListeners@http://localhost:8081/ ...

I tried with WebSocket and I works without issues.

outaTiME commented 5 years ago

Hi @iamchathu, same here when running on android, I'm using "reconnecting-websocket" version "4.1.6".

Here is the stacktrace, this code is generated from rollup and does not exits in original source.

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_d[0]')]
- node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:561:56 in _addListeners
- node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:447:12 in <unknown>
- ... 12 more stack frames from framework internals

Original code:

https://github.com/pladaria/reconnecting-websocket/blob/5074de85b0d1ba94190260a32be5453bcd4e30e1/reconnecting-websocket.ts#L484

Generated code from rollup:

https://github.com/pladaria/reconnecting-websocket/blob/5074de85b0d1ba94190260a32be5453bcd4e30e1/dist/reconnecting-websocket-cjs.js#L556

The interesting thing is if I enable the remote debugging the code works as expected without issues, but without debugging enabled the code is unable to resolve __read(_c.value, 2) statement.

I'm running react-native in expo environment using the following versions:

I try to keep looking if I found something else, but once again I think the problem is the Rollup module bundler.

Possibly this routine _removeListeners from source has the same problem too.

pladaria commented 5 years ago

Latest release (v4.1.7) includes a simpler _addListeners function (it was previously iterating a Map using for..of). Hopefully with this version the compiled code should be easier to follow.

Please, let me know if you try it

outaTiME commented 5 years ago

Great @pladaria,

im digging into the original cause of the issue and problem is related with Symbol and probably it fails in spread method of cjs file when debug option is enable.

https://github.com/facebook/react-native/issues/4676

Symbol is not defined on android, one alternative is toimport 'core-js/es6/symbol' polyfill on android.

btw you release the version v4.1.7 in NPM? or i try directly with the source code?

thanks !!

pladaria commented 5 years ago

@outaTiME just published!

outaTiME commented 5 years ago

@pladaria, yup last version works great without errors, but _debug method still using __spread internal which references to Symbol you need to be careful.

https://github.com/pladaria/reconnecting-websocket/blob/master/dist/reconnecting-websocket-cjs.js#L33

btw, i can confirm if i do the following imports the version 4.1.6 works as expected without issues (if you want to keep using for...of Map).

import 'core-js/es6/map';
import 'core-js/es6/symbol';
import 'core-js/fn/symbol/iterator';

Thanks !!!

iamchathu commented 5 years ago

@pladaria 4.1.7 fix this issue. Thank you.

@outaTiME Off topic. Can I know how you got the stacktrace?

pladaria commented 5 years ago

@outaTiME thanks for the tip but I prefer to keep the library light and dependency free. I've also replaced spread operator usage for apply (v4.1.8)

Thank you all for reporting and investigating this issue!

outaTiME commented 5 years ago

Great @pladaria, thanks once for your time the v4.1.8 version works great without issues 👍 👍

@iamchathu The stacktrace cames from react native console not from application UI (im using Expo but it works in the same way as react native)