[SignalR] Server stops sending ping message to the client
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
The server stops sending ping messages to the client, which causes the connection to abort.
I tried to dig into how the ping message might be getting blocked by combing through https://github.com/dotnet/aspnetcore/blob/bec278eabea54f63da15e10e654bdfa4168a2479/src/SignalR/server/Core/src/HubConnectionContext.cs
```c#
private ValueTask TryWritePingAsync()
{
// Don't wait for the lock, if it returns false that means someone wrote to the connection
// and we don't need to send a ping anymore
if (!_writeLock.Wait(0))
{
return default;
}
// TODO: cancel?
return new ValueTask(TryWritePingSlowAsync());
}
private async Task TryWritePingSlowAsync()
{
try
{
if (_connectionAborted)
{
return;
}
await _connectionContext.Transport.Output.WriteAsync(_cachedPingMessage);
Log.SentPing(_logger);
}
catch (Exception ex)
{
CloseException = ex;
Log.FailedWritingMessage(_logger, ex);
AbortAllowReconnect();
}
finally
{
_writeLock.Release();
}
}
```
I have a feeling it is getting hung up on
```c#
await _connectionContext.Transport.Output.WriteAsync(_cachedPingMessage); // maybe it's not actually writing
```
or on
```c#
if (!_writeLock.Wait(0)) // _writeLock could be deadlocked
```
But I don't know for sure.
Are there any steps I can take to help narrow down the cause?
So far, I've failed to reproduce this bug in test project
### Expected Behavior
The server should never stop sending ping messages to the client. In the event it cannot, it would be nice if there were logs indicating why the ping message isn't being sent.
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
7.0.102
### Anything else?
client: @microsoft/signalr@7.0.2
This bug has been occurring in our project for over a year now.
Contributor guide
Assessment
This issue has not been assessed yet.