Lock around heartbeat handler (#1264)

This commit is contained in:
BrennanConroy 2018-01-03 12:29:25 -08:00 committed by GitHub
parent 6baee8b7a9
commit d5d159eb5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -75,14 +75,20 @@ namespace Microsoft.AspNetCore.Sockets
public void OnHeartbeat(Action<object> action, object state)
{
_heartbeatHandlers.Add((action, state));
lock (_heartbeatHandlers)
{
_heartbeatHandlers.Add((action, state));
}
}
public void TickHeartbeat()
{
foreach (var (handler, state) in _heartbeatHandlers)
lock (_heartbeatHandlers)
{
handler(state);
foreach (var (handler, state) in _heartbeatHandlers)
{
handler(state);
}
}
}