dotnet / dotnet/aspnetcore

Call `onClosed` or provide an `onStopped` method to be called when the connection is stopped in certain cases

Open
#55,765 0 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I was running a Flutter app that uses on its android side the signalr java client.
In the android side (the java client), I listen to the [onClosed](https://github.com/dotnet/aspnetcore/blob/35e82e671453ee06e5a152b5cc69e0e355d60ec6/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L856) callback from the java client to schedule automatice reconnects in my app.
I was doing a heavy download on my wifi network which was taking the bandwidth from all other apps including my app mentioned above, so the [activatePingTimer](https://github.com/dotnet/aspnetcore/blob/35e82e671453ee06e5a152b5cc69e0e355d60ec6/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L1466) method appears to have timedout and called the [private stop method](https://github.com/dotnet/aspnetcore/blob/35e82e671453ee06e5a152b5cc69e0e355d60ec6/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L1473C29-L1473C105).
The problem is that this private `stop` method, does not call the `onClosed` callback registered by my app, so my app never knew the connection was closed so that it can reschedule an auto-reconnect.
I know that the `onClosed` callback is documented as
> Registers a callback to run when the connection is closed.

But does not this case indicate that connection is closed?
If this is a bug, then the private `stop` method should call the `onClosed` callbacks.
Else if this is how its intended to work, then can you provide a way to listen to when the connection stops?
(Whats the difference anyway between "stop" and "close", other than that "close" disposes the resources associated with the object?)

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

Here is a part of the logs
```
I/HubConnection( 2748): HubConnection started.
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
E/HubConnection( 2748): HubConnection disconnected with an error: Server timeout elapsed without receiving a message from the server..
I/OkHttpWebSocketWrapper( 2748): WebSocket closing with status code '1000' and reason ''.
E/HubConnection( 2748): HubConnection disconnected with an error Server timeout elapsed without receiving a message from the server..
I/HubConnection( 2748): HubConnection stopped.
I/WebSocketTransport( 2748): WebSocket connection stopped.
```
(I removed my app logs from the logs above)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.