@@ -90,12 +90,12 @@ public HubLifetime([Range(1, 10)] byte tps, IHubController hubController,
9090 {
9191 using ( await _liveControlClientsLock . LockAsyncScoped ( ) )
9292 {
93- if ( _liveControlClients . Contains ( controller ) )
93+ if ( _liveControlClients . Contains ( controller ) )
9494 {
9595 _logger . LogWarning ( "Client already registered, not sure how this happened, probably a bug" ) ;
9696 return null ;
9797 }
98-
98+
9999 _liveControlClients = _liveControlClients . Add ( controller ) ;
100100 }
101101
@@ -120,21 +120,21 @@ public async Task<bool> RemoveLiveControlClient(LiveControlController controller
120120
121121 private async Task DisposeLiveControlClients ( )
122122 {
123- foreach ( var client in _liveControlClients )
123+ ImmutableArray < LiveControlController > liveControlClients ;
124+ using ( await _liveControlClientsLock . LockAsyncScoped ( ) )
124125 {
125- try
126- {
127- await client . DisposeAsync ( ) ;
128- }
129- catch ( Exception e )
130- {
131- _logger . LogError ( e , "Error disposing live control client" ) ;
132- }
126+ liveControlClients = _liveControlClients ;
127+ _liveControlClients = _liveControlClients . Clear ( ) ; // Returns just an empty lol
133128 }
134129
135- using ( await _liveControlClientsLock . LockAsyncScoped ( ) )
130+ try
131+ {
132+ await Task . WhenAll ( liveControlClients . Select ( client => client . HubDisconnected ( ) ) ) ;
133+ }
134+ catch ( Exception e )
136135 {
137- _liveControlClients = _liveControlClients . Clear ( ) ;
136+ // We dont expect any errors here, but if there is a bug then this might happen, and it would be cat
137+ _logger . LogError ( e , "Error disposing live control client" ) ;
138138 }
139139 }
140140
@@ -160,7 +160,7 @@ public async Task<bool> InitAsync(CancellationToken cancellationToken)
160160#pragma warning restore CS4014
161161
162162 _state = HubLifetimeState . Idle ; // We are fully setup, we can go back to idle state
163-
163+
164164 return true ;
165165 }
166166
@@ -269,7 +269,7 @@ public async Task UpdateDevice()
269269 {
270270 await using var db = await _dbContextFactory . CreateDbContextAsync ( _cancellationSource . Token ) ;
271271 await UpdateShockers ( db , _cancellationSource . Token ) ;
272-
272+
273273 foreach ( var websocketController in _liveControlClients )
274274 await websocketController . UpdatePermissions ( db ) ;
275275 }
@@ -429,11 +429,10 @@ public async ValueTask DisposeAsync()
429429 {
430430 if ( _disposed ) return ;
431431 _disposed = true ;
432-
432+
433433 await _cancellationSource . CancelAsync ( ) ;
434434 await DisposeLiveControlClients ( ) ;
435435 }
436-
437436}
438437
439438/// <summary>
0 commit comments