Skip to content

Commit 887093d

Browse files
committed
Try to resolve unregister concurrency issues
1 parent 1c7c56e commit 887093d

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

LiveControlGateway/Controllers/LiveControlController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public LiveControlController(
9393
_pingTimer.Elapsed += (_, _) => OsTask.Run(SendPing);
9494
}
9595

96-
97-
private volatile bool _unregistered;
96+
97+
private bool _unregistered;
9898

9999
/// <inheritdoc />
100100
protected override async Task UnregisterConnection()
101101
{
102-
if (_unregistered) return;
103-
_unregistered = true;
102+
if (Interlocked.Exchange(ref _unregistered, true))
103+
return;
104104

105105
if (_hubLifetime == null) return;
106106
if (!await _hubLifetime.RemoveLiveControlClient(this))
@@ -307,7 +307,7 @@ private async Task IntakePong(JsonDocument? _)
307307
{
308308
Logger.LogTrace("Intake pong");
309309

310-
// Received pong without sending ping, this could be abusing the pong endpoint.
310+
// Received pong without sending ping, this could be abusing the pong endpoin>t.
311311
if (_pingTimestamp == 0)
312312
{
313313
// TODO: Kick or warn client.
@@ -535,6 +535,7 @@ await QueueMessage(new LiveControlResponse<LiveResponseType>
535535
[NonAction]
536536
public async Task HubDisconnected()
537537
{
538+
Interlocked.Exchange(ref _unregistered, true);
538539
_unregistered = true; // The hub lifetime has already unregistered us
539540

540541
Logger.LogTrace("Hub disconnected, disposing controller");

0 commit comments

Comments
 (0)