Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/BootstrapBlazor/Services/DefaultNetworkMonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ public async Task RegisterStateChangedCallback(IComponent component, Func<Networ
await _semaphoreSlim.WaitAsync(3000);
if (!_init)
{
_init = true;
try
{
_init = true;

_networkModule ??= await _runtime.LoadModuleByName("net");
await _networkModule.InvokeVoidAsync("init", new
_networkModule ??= await _runtime.LoadModuleByName("net");
await _networkModule.InvokeVoidAsync("init", new
{
Invoke = _interop,
OnNetworkStateChangedCallback = nameof(TriggerNetworkStateChanged)
});
Comment on lines +61 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The try/finally block now only releases the semaphore if _init was false.

If _init is true, the semaphore is not released, which may cause deadlocks on subsequent RegisterStateChangedCallback calls. Ensure _semaphoreSlim.Release() is always called to prevent this.

}
finally
{
Invoke = _interop,
OnNetworkStateChangedCallback = nameof(TriggerNetworkStateChanged)
});
_semaphoreSlim.Release();
}
}
_semaphoreSlim.Release();
}
}

Expand Down
Loading