jhen0409 / remotedev-rn-debugger

Injecting remotedev-app monitor into official Remote debugger of React Native. (formerly remote-redux-devtools-on-debugger)
MIT License
244 stars 28 forks source link

SocketProtocolError: Socket connection failed for unknown reason. #15

Open kevinblade opened 8 years ago

kevinblade commented 8 years ago

I encountered the error on my RN app. When this error occur the React Native Debugger's Inspector is cleared. I think this problem is related other node modules but I can't find what it is. Stacktrace shows source code location is devTools.js:219 in remote-redux-devtools module. What's the problem?

zalmoxisus commented 8 years ago

As you mentioned, the warning comes from here, notifying that "Socket connection failed for unknown reason". Maybe @jondubois has any clues why it's unknown reason or how to debug it further.

jondubois commented 8 years ago

@kevinblade If you modify https://github.com/zalmoxisus/remote-redux-devtools/blob/master/src/devTools.js#L203 to listen to the 'disconnect' event like socket.on('disconnect', function (statusCode, reason) {});what is the statusCode - Also check the reason?

@zalmoxisus Basically it means that the SC client received a status code that it didn't understand. Since v5 of the client, it should provide a better description for these errors (in v5 it should provide the reason as part of the 'error' message). In v4, you have to listen to the 'disconnect' event to get the reason.

kevinblade commented 8 years ago

@jondubois As you mentioned I tried to test with 'disconnect' event handler. But the statusCode and reason are 'unknown' too. I don't know what it is. Did you have done it?

jondubois commented 8 years ago

@zalmoxisus @kevinblade Maybe it's related to the fact that the SocketCluster client and server versions are different. v4 client should be compatible with v5 server but this might be an edge case.

It sounds like there are two problems here:

You can try upgrading the socketcluster-client dependency to v5.0.9 and see if that fixes things (or at least it should show you a proper error).

Maybe it's just that the hostname is incorrect and the client cannot reach the server or something like that.

kevinblade commented 8 years ago

@jondubois I tested with your recommendation my local remote-redux-devtools's socketcluster-client dependency is upgraded to v5.0.9. But this problem is not discovered or cleared. How can I fix it? I want to use this package so I need your help.

kevinblade commented 8 years ago

I fixed this problem. ^^ My fixing is as follows.

Step 1: Downgrade the version of remote-redux-devtools to 0.3.3 and remote-redux-devtools-on-debugger to 0.5.1 Step 2: Reinstall above two packages. Step 3: Change socketcluster's version to 4.3.1 in remotedev-server's package.json. Step 4: Remove socketcluster in remotedev-server and then npm install in remotedev-server for reinstall it.

That's it. But after that I don't know reason why I can't use --injectserver for postintall option in root package.json so I use --runserver. Thank you @jondubois for your mentions that is a good hint for my fixing. Anyway I can use this useful package on my project.

zalmoxisus commented 8 years ago

@kevinblade, what versions of remotedev-server, socketcluster and socketcluster-client do you have now?

kevinblade commented 8 years ago
screen shot 2016-09-08 at 17 19 24

In my case, these combinations are correct. I changed local remotedev-server's package.json for downgrading of socketcluster from 5.0.4 to 4.3.1 and then reinstall remotedev-server's modules. After that my problem was cleared.

zalmoxisus commented 8 years ago

@kevinblade, thanks for clarifying that. So, the problem comes from socketcluster@5.

jondubois commented 8 years ago

I tested using the socketcluster v5.0.11 (socketcluster-server 5.1.0) and socketcluster-client v4.3.19 and it's working correctly for me (even with the client version mismatch).

The only way I was able to reproduce the Uncaught Socket error - SocketProtocolError: Socket connection failed for unknown reasons was by disconnecting the socket from the server side using socket.disconnect(4222) (where 4222 is a custom error code I made up) - That's expected though because if you use a custom error code without providing an error message as second argument, the client won't recognize it will just emit an unknown error. You can call socket.disconnect() without arguments - Then the statusCode will be 1000 which is the default.

I'm not sure if that's the problem in this case though.

zalmoxisus commented 8 years ago

Could it be because the SC server and client versions are different?

@jondubois, I'm using it without problems as well, but for web apps, not React Native. The worker code is pretty simple. Maybe you can spot any problems there?

@kevinblade, is the problem only when using injectserver argument? Does that happens when using runserver with the initial lib?

zalmoxisus commented 8 years ago

@kevinblade, I just shipped 0.4.8 of remote-redux-devtools. It should reconnect when such errors occur. Also the errors appear only in the console now. Please let me know whether it helps.

jondubois commented 8 years ago

@zalmoxisus It looks fine at first glance.

kevinblade commented 8 years ago

@zalmoxisus Yes, injectserver argument produces the problem which is babel parsing error but runserver is not.

jhen0409 commented 8 years ago

Yes, injectserver argument produces the problem which is babel parsing error but runserver is not.

@kevinblade could you provide your React Native version? I can't get some parsing errors for injectserver argument.

kevinblade commented 8 years ago

@jhen0409 My RN version is 0.32.1

mmmurf commented 8 years ago

Is there a recommended fix for this?

zalmoxisus commented 8 years ago

@mmmurf, could you provide a repo to reproduce the problem? Or you could try to reproduce it with this example and provide steps so I could replicate and investigate that.

To debug it yourself, use remotedev-server, so you'll see what causes the issue on backend.

mmmurf commented 8 years ago

@zalmoxisus sure I'll do one of those things asap.

jondubois commented 8 years ago

I'll try to get my hands on a Mac this week to debug SC with RN. Last time I tried setting up RN on Ubuntu, it was a disaster.

zalmoxisus commented 8 years ago

@jondubois I'm using a mac but cannot reproduce it unfortunately. Maybe @mmmurf can reproduce it with the example I indicated above and provide some steps.