Skip to content

Server stop hang on android #195

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

Closed
kishanDevani opened this issue Aug 5, 2013 · 11 comments
Closed

Server stop hang on android #195

kishanDevani opened this issue Aug 5, 2013 · 11 comments

Comments

@kishanDevani
Copy link

how i do it....

@DeHecht
Copy link

DeHecht commented Aug 5, 2013

i faced the same problem #191 may this help you?

@Davidiusdadi
Copy link
Collaborator

hang has been fixed
see #191

@kishanDevani
Copy link
Author

hi......
i not clear ....
please help me....

@kishanDevani
Copy link
Author

this web socket server work very well but problem only occurs when stooping them...

@Davidiusdadi
Copy link
Collaborator

Do you work on the latest revision?

I will try to reproduce the problem within the next few days.

@Davidiusdadi Davidiusdadi reopened this Aug 20, 2013
@DeHecht
Copy link

DeHecht commented Sep 4, 2013

One of our testers reproduced an deadlock within the library.

"WebsocketSelector328":
    at org.java_websocket.server.WebSocketServer.removeConnection(WebSocketServer.java:519)
    - waiting to lock <0x00000007ae49fcd8> (a java.util.HashSet)
    at org.java_websocket.server.WebSocketServer.onWebsocketClose(WebSocketServer.java:498)
    at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:470)
    - locked <0x00000007ae555d00> (a org.java_websocket.WebSocketImpl)
    at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:490)
    at org.java_websocket.SocketChannelIOHelper.batch(SocketChannelIOHelper.java:64)
    - locked <0x00000007ae555d00> (a org.java_websocket.WebSocketImpl)
    at org.java_websocket.server.WebSocketServer.run(WebSocketServer.java:349)
    at java.lang.Thread.run(Thread.java:662)
"main":
    at org.java_websocket.WebSocketImpl.flushAndClose(WebSocketImpl.java:498)
    - waiting to lock <0x00000007ae555d00> (a org.java_websocket.WebSocketImpl)
    at org.java_websocket.WebSocketImpl.close(WebSocketImpl.java:424)
    at org.java_websocket.WebSocketImpl.close(WebSocketImpl.java:537)
    at org.java_websocket.server.WebSocketServer.stop(WebSocketServer.java:209)
    - locked <0x00000007ae49fcd8> (a java.util.HashSet)

so my suggested quick solution would be to replace

synchronized ( connections ) {
    for(WebSocket ws : socketsToClose) {
        ws.close( CloseFrame.GOING_AWAY );
    }
}

with

List<WebSocket> socketsToClose = null;

// copy the connections in a list (prevent callback deadlocks)
synchronized ( connections ) {
    socketsToClose = new ArrayList<WebSocket>(connections);
}

for(WebSocket ws : socketsToClose) {
    ws.close( CloseFrame.GOING_AWAY );
}

this way the HashSet would not get accessed by two different threads at the same time resulting into the deadlock.

Davidiusdadi added a commit to Davidiusdadi/Java-WebSocket that referenced this issue Sep 4, 2013
@kishanDevani
Copy link
Author

it still hang app on android, today i replace all new code....!

@kishanDevani
Copy link
Author

i am working on this app....!

https://play.google.com/store/apps/details?id=com.spidren.inc

@kishanDevani
Copy link
Author

it now hang on when not conected any clicent..!

@bendem
Copy link
Contributor

bendem commented Aug 8, 2015

Probably fixed by #329

@marci4
Copy link
Collaborator

marci4 commented May 15, 2017

Looks like this issue is fixed with #329

Closing!
Greetings
marci4

@marci4 marci4 closed this as completed May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants