Skip to content

Commit eb26592

Browse files
authored
Fix: Race condition on host/port scanned (#3287)
* Fix: Race condition on host/port scanned * Docs: #3287
1 parent f550c81 commit eb26592

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ private async Task DetectIPRange()
536536
{
537537
IsSubnetDetectionRunning = true;
538538

539-
var localIP = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync(IPAddress.Parse("1.1.1.1"));
539+
var localIP = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync(IPAddress.Parse(GlobalStaticConfiguration.Dashboard_PublicIPv4Address));
540540

541541
// Could not detect local ip address
542542
if (localIP != null)
@@ -716,7 +716,9 @@ public void OnClose()
716716
private void HostScanned(object sender, IPScannerHostScannedArgs e)
717717
{
718718
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
719-
new Action(delegate { Results.Add(e.Args); }));
719+
new Action(delegate {
720+
Results.Add(e.Args);
721+
}));
720722
}
721723

722724
/// <summary>
@@ -736,14 +738,19 @@ private void ProgressChanged(object sender, ProgressChangedArgs e)
736738
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
737739
private void ScanComplete(object sender, EventArgs e)
738740
{
739-
if (Results.Count == 0)
741+
// Run in UI thread with lower priority than HostScanned event
742+
// to ensure all results are added first #3285
743+
Application.Current.Dispatcher.Invoke(() =>
740744
{
741-
StatusMessage = Strings.NoReachableHostsFound;
742-
IsStatusMessageDisplayed = true;
743-
}
745+
if (Results.Count == 0)
746+
{
747+
StatusMessage = Strings.NoReachableHostsFound;
748+
IsStatusMessageDisplayed = true;
749+
}
744750

745-
IsCanceling = false;
746-
IsRunning = false;
751+
IsCanceling = false;
752+
IsRunning = false;
753+
}, DispatcherPriority.Background);
747754
}
748755

749756
/// <summary>

Source/NETworkManager/ViewModels/PortScannerViewModel.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,19 @@ private void ProgressChanged(object sender, ProgressChangedArgs e)
565565

566566
private void ScanComplete(object sender, EventArgs e)
567567
{
568-
if (Results.Count == 0)
568+
// Run in UI thread with lower priority than PortScanned event
569+
// to ensure all results are added first #3285
570+
Application.Current.Dispatcher.Invoke(() =>
569571
{
570-
StatusMessage = Strings.NoOpenPortsFound;
571-
IsStatusMessageDisplayed = true;
572-
}
572+
if (Results.Count == 0)
573+
{
574+
StatusMessage = Strings.NoOpenPortsFound;
575+
IsStatusMessageDisplayed = true;
576+
}
573577

574-
IsCanceling = false;
575-
IsRunning = false;
578+
IsCanceling = false;
579+
IsRunning = false;
580+
}, DispatcherPriority.Background);
576581
}
577582

578583
private void UserHasCanceled(object sender, EventArgs e)

Website/docs/changelog/next-release.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ Release date: **xx.xx.2025**
8484

8585
## Bug Fixes
8686

87+
**IP Scanner**
88+
89+
- Fix race condition when scan is complete but not all results have been processed yet, causing a wrong error message to be displayed. [#3287](https://github.com/BornToBeRoot/NETworkManager/pull/3287)
90+
91+
**Port Scanner**
92+
93+
- Fix race condition when scan is complete but not all results have been processed yet, causing a wrong error message to be displayed. [#3287](https://github.com/BornToBeRoot/NETworkManager/pull/3287)
94+
8795
**PowerShell**
8896

8997
- Resolve the actual path to `pwsh.exe` under `C:\Program Files\WindowsApps\` instead of relying on the stub located at `%LocalAppData%\Microsoft\WindowsApps\`. The stub simply redirects to the real executable, and settings such as themes are applied only to the real binary via the registry. [#3246](https://github.com/BornToBeRoot/NETworkManager/pull/3246)

0 commit comments

Comments
 (0)