TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.54k stars 2.58k forks source link

Secure websocket closes after a few minutes #200

Closed galdolber closed 7 years ago

galdolber commented 11 years ago

I'm not doing anything special, just connecting and waiting and I get this:

close with code: 1006 java.lang.NullPointerException at org.java_websocket.drafts.Draft_10.acceptHandshakeAsClient(Draft_10.java:71) at org.java_websocket.WebSocketImpl.decodeHandshake(WebSocketImpl.java:264) at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:159) at org.java_websocket.client.WebSocketClient.interruptableRun(WebSocketClient.java:239) at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:188) at posplugin.client.proxy$org.java_websocket.client.WebSocketClient$0.run(Unknown Source) at java.lang.Thread.run(Thread.java:680)

Davidiusdadi commented 11 years ago

Very strange. Please give me more infos.

Do you use a special port? What server are you connecting to; the JavaWebsocketServer? Was a proxy somehow involved?

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g. without sending or receiving a Close control frame.

So i assume that the NullPointerException caused you client to go down - which definitively is a bug.

I however wander that

after a few minutes

the connection still has not been established but the opening handshake is being performed.

Can you confirm that you never transferred a single byte over that connection?

Please also pull from https://github.com/Davidiusdadi/Java-WebSocket.git from and post an updated stacktrace. That branch has the latest bugfixes applied and will be merged soon.

galdolber commented 11 years ago

I'm using nginx in the server (for the ssl) and httpkit behind it.

No special port: wss://my.server.com

Yes, for now I'm just connecting. I get the open event, and after a few minutes of not sending any data I get the exception.

On Wed, Aug 14, 2013 at 10:33 AM, David Rohmer notifications@github.comwrote:

Very strange. Please give me more infos.

Do you use a special port? What server are you connecting to; the JavaWebsocketServer? Was a proxy somehow involved?

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g. without sending or receiving a Close control frame.

So i assume that the NullPointerException caused you client to go down - which definitively is a bug.

I however wander that

after a few minutes

the connection still has not been established but the opening handshake is being performed.

Can you confirm that you never transferred a single byte over that connection?

Please also pull from https://github.com/Davidiusdadi/Java-WebSocket.gitfrom and post an updated stacktrace. That branch has the latest bugfixes applied and will be merged soon.

— Reply to this email directly or view it on GitHubhttps://github.com/TooTallNate/Java-WebSocket/issues/200#issuecomment-22652629 .

A world citizen

galdolber commented 11 years ago

Ok, found the problem. Is the _proxy_readtimeout configuration on nginx.

On Wed, Aug 14, 2013 at 11:11 AM, Gal Dolber gal.dolber@gmail.com wrote:

I'm using nginx in the server (for the ssl) and httpkit behind it.

No special port: wss://my.server.com

Yes, for now I'm just connecting. I get the open event, and after a few minutes of not sending any data I get the exception.

On Wed, Aug 14, 2013 at 10:33 AM, David Rohmer notifications@github.comwrote:

Very strange. Please give me more infos.

Do you use a special port? What server are you connecting to; the JavaWebsocketServer? Was a proxy somehow involved?

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g. without sending or receiving a Close control frame.

So i assume that the NullPointerException caused you client to go down - which definitively is a bug.

I however wander that

after a few minutes

the connection still has not been established but the opening handshake is being performed.

Can you confirm that you never transferred a single byte over that connection?

Please also pull from https://github.com/Davidiusdadi/Java-WebSocket.gitfrom and post an updated stacktrace. That branch has the latest bugfixes applied and will be merged soon.

— Reply to this email directly or view it on GitHubhttps://github.com/TooTallNate/Java-WebSocket/issues/200#issuecomment-22652629 .

A world citizen

A world citizen

Davidiusdadi commented 11 years ago

Also you found the problem on your side please help me fix the problem on mine. I want to know what caused the nullpointer exception.

Please put this line at the start of your application WebSocketImpl.DEBUG = true;

,reproduce the problem once more

and post the command line output as a comment on this issue.

galdolber commented 11 years ago

rite(158): {GET / HTTP/1.1 Connection: Upgrade Host: my.server.com:443 Sec-WebSocket-Key: xbKYiYgMPxoeBHC4jajRKA== Sec-WebSocket-Version: 8 Upgrade: websocket

} process(200): {HTTP/1.1 101 Switching Protocols Server: nginx Date: Wed, 14 Aug 2013 18:39:01 GMT Content-Length: 0 Connection: upgrade Sec-Websocket-Accept: SiwNQRGDlakbfQRhSu+jlv+flcM= Upgrade: websocket

} open using draft: Draft_10 open close 1006 process(16384): {too big to display} java.lang.NullPointerException at org.java_websocket.drafts.Draft_10.acceptHandshakeAsClient(Draft_10.java:71) at org.java_websocket.WebSocketImpl.decodeHandshake(WebSocketImpl.java:264) at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:159) at org.java_websocket.client.WebSocketClient.interruptableRun(WebSocketClient.java:239) at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:188) at posplugin.client.proxy$org.java_websocket.client.WebSocketClient$0.run(Unknown Source) at java.lang.Thread.run(Thread.java:680)

On Wed, Aug 14, 2013 at 11:35 AM, Gal Dolber gal.dolber@gmail.com wrote:

write(158): {GET / HTTP/1.1 Connection: Upgrade Host: backend.zuldi.co:443 Sec-WebSocket-Key: xbKYiYgMPxoeBHC4jajRKA== Sec-WebSocket-Version: 8 Upgrade: websocket

} process(200): {HTTP/1.1 101 Switching Protocols Server: nginx Date: Wed, 14 Aug 2013 18:39:01 GMT Content-Length: 0 Connection: upgrade Sec-Websocket-Accept: SiwNQRGDlakbfQRhSu+jlv+flcM= Upgrade: websocket

} open using draft: Draft_10 open close 1006 process(16384): {too big to display} java.lang.NullPointerException at org.java_websocket.drafts.Draft_10.acceptHandshakeAsClient(Draft_10.java:71) at org.java_websocket.WebSocketImpl.decodeHandshake(WebSocketImpl.java:264) at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:159) at org.java_websocket.client.WebSocketClient.interruptableRun(WebSocketClient.java:239) at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:188) at posplugin.client.proxy$org.java_websocket.client.WebSocketClient$0.run(Unknown Source) at java.lang.Thread.run(Thread.java:680)

On Wed, Aug 14, 2013 at 11:26 AM, David Rohmer notifications@github.comwrote:

Also you found the problem on your side please help me fix the problem on mine. I want to know what caused the nullpointer exception.

Please put this line at the start of your application WebSocketImpl.DEBUG = true;

,reproduce the problem once more

and post the command line output as a comment on this issue.

— Reply to this email directly or view it on GitHubhttps://github.com/TooTallNate/Java-WebSocket/issues/200#issuecomment-22656376 .

A world citizen

A world citizen

tmbo commented 10 years ago

@Davidiusdadi did you have time to look into the issue? we ran into the same problem. Since we are also using nginx, I guess we are facing the same cause.

BenDavidJamin commented 10 years ago

+1

kanelr commented 9 years ago

Did you fix this bug? I run this socket standard alone java.lang.NullPointerException at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:321) at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:158) at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:709) 2015-09-11 09:52:24,455 ERROR [MainSicbo] onError java.lang.InterruptedException at java.lang.Object.wait(Native Method) at java.lang.Thread.join(Thread.java:1186) at java.lang.Thread.join(Thread.java:1239) at org.java_websocket.server.WebSocketServer.stop(WebSocketServer.java:229) at org.java_websocket.server.WebSocketServer.stop(WebSocketServer.java:235) at org.java_websocket.server.WebSocketServer.handleFatal(WebSocketServer.java:464) at org.java_websocket.server.WebSocketServer.access$100(WebSocketServer.java:51) at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:716)

marci4 commented 7 years ago

Hello everyone,

is this with the latest version still an issue?

Since the codebase changed a lot, I cannot use stacktrace.

Greetings marci4

ikermart commented 7 years ago

@marci4 I seems that still closes the server. I have a timer, that every 3 seconds sends data to websocket server from my android app. I have an event that in certain moment stops sending data (semaphor), If i restarted sending data before 5 minutes, the server response ok, but if the stop is more than 5 minutes, I send the request but not onMessage is called neither onError. Is there a internal timeout configuration?

marci4 commented 7 years ago

Hello @ikermart,

no there is no internal timeout configuration right now! With the upcoming release of 1.3.4 I will add a feature which automatically detects lost connections. I will also change the implementation of your SSLSocketChannel which may also fix this!

Greetings marci4

marci4 commented 7 years ago

Any update?

marci4 commented 7 years ago

No feedback for months!

Please open a separate issue if you still have any problem! Greetings marci4