aspnet / SignalR

[Archived] Incredibly simple real-time web for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
2.38k stars 446 forks source link

Java client: NullPointerException in thread "OkHttp Dispatcher" when connection timeout #3303

Closed a-konyaev closed 5 years ago

a-konyaev commented 6 years ago

I have been trying to connect to server through proxy and have gotten connection timeout. But during handle that error java-client library failed with NPE:

Exception in thread "OkHttp Dispatcher" java.lang.NullPointerException
    at com.microsoft.signalr.HubConnection.stopConnection(HubConnection.java:431)
    at com.microsoft.signalr.HubConnection.lambda$null$6(HubConnection.java:301)
    at com.microsoft.signalr.WebSocketTransport.onClose(WebSocketTransport.java:93)
    at com.microsoft.signalr.WebSocketTransport.lambda$start$24(WebSocketTransport.java:56)
    at com.microsoft.signalr.OkHttpWebSocketWrapper$SignalRWebSocketListener.onFailure(OkHttpWebSocketWrapper.java:98)
    at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570)
    at okhttp3.internal.ws.RealWebSocket$2.onFailure(RealWebSocket.java:220)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:161)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

There is error in method com.microsoft.signalr.HubConnection#stopConnection at line: https://github.com/aspnet/SignalR/blob/release/2.2/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java#L431 connectionState is null when this line is executing.

My client code:

        HubConnection hubConnection = HubConnectionBuilder
                .create("http://some-server")
                .build();
        hubConnection.start()
                .timeout(10, TimeUnit.SECONDS)
                .blockingAwait();
mikaelm12 commented 5 years ago

Yeah, it looks like when there is a failure to fully connect the connectionState variable doesn't get set and so when we try to clean up the outstanding invocations in the stopConnection logic we don't check if connectionState was initialized. Thanks for filing the issue!

mikaelm12 commented 5 years ago

Done: ff385f71c592ff218956cfa3b1b0a184604b8409