Skip to content

[SignalR] java.lang.NullPointerException thrown in HubConnection (Java Client) #24367

@petermcc0807nw

Description

@petermcc0807nw

Hi,

I have an ASP.NET Core service, targeting the .NET Core 3.1.6 runtime, running on a Windows 10 (v10.0.18362) development machine.

I also have an Android 9.0 client which connects to the service via SignalR (com.microsoft.signalr:signalr:5.0.0-preview.7.20365.19)

If I repeatedly (and quite randomly) restart the service and app, resulting in continuous SignalR connects / disconnects, I will eventually crash the app with a FATAL EXCEPTION similar to the following logcat dump:

2020-07-28 12:34:15.029 27132-27229/com.foo.bar E/AndroidRuntime: FATAL EXCEPTION: Timer-2
    Process: com.foo.bar, PID: 27132
    java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.Timer.cancel()' on a null object reference
        at com.microsoft.signalr.HubConnection$1.run(HubConnection.java:422)
        at java.util.TimerThread.processTask(Timer.java:569)
        at java.util.TimerThread.mainLoop(Timer.java:527)
        at java.util.TimerThread.run(Timer.java:512)
2020-07-28 12:34:15.079 27132-27229/com.foo.bar I/Process: Sending signal. PID: 27132 SIG: 9

I’ve taken a quick look at the HubConnection.java source code and noticed that the stopConnection method does the following:

if (pingTimer != null) {
	pingTimer.cancel();
	pingTimer = null;
}

Then, in the activatePingTimer method, the catch block (within the pingTimer scheduled TimerTask) simply calls:

pingTimer.cancel();

without checking if pingTimer is null. If the stopConnection method has already set pingTimer to null, could this could be cause of the FATAL EXCEPTION I’m seeing? It feels like it.

Thanks.

Metadata

Metadata

Assignees

Labels

area-signalrIncludes: SignalR clients and serversbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions