Search code examples
javaspringwebsocketsockjs

No Websocket connection without internet access (Ubuntu)


I have a Spring Boot app, which implements a Websocket server (SockJS).

I can connect clients to that server just fine on my local network, as long as the Ubuntu machine, which is hosting the app, has internet access.

2016-10-27 11:22:20.802 DEBUG 9390 --- [nio-8085-exec-9] o.a.coyote.http11.Http11NioProtocol : Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@6cb31793:org.apache.tomcat.util.net.NioChannel@231c3b0c:java.nio.channels.SocketChannel[connected local=/192.168.1.104:8085 remote=/192.168.1.106:51946]], Status in: [OPEN_READ], State out: [CLOSED]

2016-10-27 11:22:20.849 DEBUG 9390 --- [io-8085-exec-10] d.f.util.ConnectivityCheckUtil : Local network interface found: wlp2s0 192.168.1.104 2016-10-27 11:22:20.850 DEBUG 9390 --- [io-8085-exec-10] d.f.util.ConnectivityCheckUtil : Your ip is: 192.168.1.104

2016-10-27 11:22:20.850 DEBUG 9390 --- [io-8085-exec-10] d.f.i.v.b.i.w.s.BrokerWebsocketHandler : Connected ... t0obkpdo 2016-10-27 11:22:20.851 INFO 9390 --- [io-8085-exec-10] d.f.i.v.b.i.w.s.BrokerWebsocketHandler : websocketTextmessagesize = 1000000

2016-10-27 11:22:20.852 DEBUG 9390 --- [io-8085-exec-10] o.a.coyote.http11.Http11NioProtocol : Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@1648207f:org.apache.tomcat.util.net.NioChannel@231c3b0c:java.nio.channels.SocketChannel[connected local=192.168.1.104/192.168.1.104:8085 remote=/192.168.1.106:51947]], Status in: [OPEN_READ], State out: [UPGRADING]

2016-10-27 11:22:20.852 DEBUG 9390 --- [io-8085-exec-10] o.a.coyote.http11.Http11NioProtocol : Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@1648207f:org.apache.tomcat.util.net.NioChannel@231c3b0c:java.nio.channels.SocketChannel[connected local=192.168.1.104/192.168.1.104:8085 remote=/192.168.1.106:51947]], Status in: [OPEN_READ], State out: [UPGRADED]

The moment I pull the WAN plug on my network router, the server drops all WS connections and won't allow new ones. The client will report the error code 2000 'All transports failed'.

The server will throw this error:

2016-10-27 11:18:38.380 DEBUG 9390 --- [nio-8085-exec-1] o.a.coyote.http11.Http11NioProtocol : Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@5526ea03:org.apache.tomcat.util.net.NioChannel@5f9486ff:java.nio.channels.SocketChannel[closed]], Status in: [OPEN_READ], State out: [CLOSED]

2016-10-27 11:18:51.396 DEBUG 9390 --- [nio-8085-exec-2] o.a.coyote.http11.Http11NioProtocol : Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@d05fac1:org.apache.tomcat.util.net.NioChannel@5f9486ff:java.nio.channels.SocketChannel[connected local=/192.168.1.104:8085 remote=/192.168.1.106:51692]], Status in: [OPEN_READ], State out: [CLOSED]

2016-10-27 11:19:01.437 DEBUG 9390 --- [nio-8085-exec-6] o.a.coyote.http11.Http11NioProtocol : Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@7f10c230:org.apache.tomcat.util.net.NioChannel@5f9486ff:java.nio.channels.SocketChannel[connected local=192.168.1.104/192.168.1.104:8085 remote=/192.168.1.106:51693]], Status in: [OPEN_READ], State out: [CLOSED]

2016-10-27 11:19:02.141 DEBUG 9390 --- [nio-8085-exec-3] d.f.util.ConnectivityCheckUtil : Local network interface found: wlp2s0 192.168.1.104

2016-10-27 11:19:02.142 DEBUG 9390 --- [nio-8085-exec-3] d.f.util.ConnectivityCheckUtil : Your ip is: 192.168.1.104

2016-10-27 11:19:02.144 DEBUG 9390 --- [nio-8085-exec-3] d.f.i.v.b.i.w.s.BrokerWebsocketHandler : Connected ... 2cbhftw3

2016-10-27 11:19:02.144 INFO 9390 --- [nio-8085-exec-3] d.f.i.v.b.i.w.s.BrokerWebsocketHandler : websocketTextmessagesize = 1000000

2016-10-27 11:19:02.147 DEBUG 9390 --- [nio-8085-exec-3] d.f.i.v.b.i.w.s.BrokerWebsocketHandler : Session 2cbhftw3 closed because of CloseStatus[code=1011, reason=null]

2016-10-27 11:19:02.149 ERROR 9390 --- [nio-8085-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=http://192.168.1.104:8085/websocket/data/421/2cbhftw3/xhr_streaming; nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: Failed to open session; nested exception is org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe] with root cause

java.io.IOException: Broken pipe

As soon as I plug the WAN cable back in and the router has internet access again, WS connections start working again. I have tried this on multiple routers from Netgear and TP-Link.

I have already tried to set the network interface settings manually under ubuntu, but that didn't help.

Any idea what might be causing this?

BR Daniel


Solution

  • I seems like you have to set a static IP or else the system tries to reach a DNS discovery service according to wire shark, which it doesn't find and just doesn't connect to the intended IP.