Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close() not working or taking a really long time #44

Open
rreghin opened this issue May 20, 2014 · 6 comments
Open

close() not working or taking a really long time #44

rreghin opened this issue May 20, 2014 · 6 comments

Comments

@rreghin
Copy link

rreghin commented May 20, 2014

Hello again!

I'm having a hard time trying to figure out why the close() method is not working properly.

When using the browser's native version of WebSocket, or the Android's 4.4.x native version (fallback) as well, the close() method works as expected, and it closes the connection right away.

But when using your plugin, it takes forever to close the connection, and eventually the server will close the connection due to innactivity.

Should I do something else other than simply calling the close() method (function) of the object??

@rreghin
Copy link
Author

rreghin commented May 23, 2014

Well, I worked a way around the problem.

Instead for using the close() method, I made a command to disconnect the client from the server side. So when the client wants to disconnect, it sends the "disconnect me" command to the server, and the server does the job.

Solved my problem, but I still wonder why the close() method would not work...

@zwz
Copy link

zwz commented Aug 22, 2014

Hi, rreghin
I find the same issue, on my android device (4.0.4).
I use ws (https://github.com/einaros/ws) as my websocket server.

The weird thing is that even the device is disconnected, when the server tries to send some message to the device, there is no error and the server still has no idea about the dead connection.

@rreghin
Copy link
Author

rreghin commented Aug 22, 2014

That's very odd. =(

Unfortunately I have no idea on how to help you.

Did you try to do the workaround I mentioned in my last post (May 23) ??

@zwz
Copy link

zwz commented Aug 23, 2014

Yes, I tried.
Did you find the same issue that when the device disconnects (before sending "disconnect me" message), the server could still "send" message with the disconnnected websocket connection?
I really hope that when the server tries to send something, there would be a error if the connection is already disconnected.

@rreghin
Copy link
Author

rreghin commented Aug 25, 2014

Yes, I had the same problem. Actually, I think this is some "TCP/IP stack" feature/issue, and I think it has nothing to do with the WebSockets itself.

Its up to the client to send a FIN packet to the server whenever it wants do disconnect. If the client does not send the FIN packet, the server has no way to know the connection is dead.

The socket function close(fd) is supposed to do the job, and I think it does it very well. But sometimes for some reason, like a network problem, the server does not receive the FIN packet. But what I think is more likely to happen is the client sends the FIN packet, the server receives it and then reply to it (with an ACK packet), as expected, but the client is already gone and won't reply back to the ACK packet. Then boom, you're server side connection is stuck in a FIN_WAIT_2 state, and there's not much you can do about it.

I solved this problem with a server keep alive packet. My server sends a tiny packet to the client every 1 or 2 minutes, and when it gets no response from the client after 2 consecutive packets it just drops the connection.

Hope it helps somehow... =)

@zwz
Copy link

zwz commented Aug 26, 2014

Thank you for your explanation.
This really helps me a lot to understand my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants