Skip to content

fix: prevent infinite hang on package loading when NCSI is stale#5128

Open
Zeroes1 wants to merge 1 commit into
Devolutions:mainfrom
Zeroes1:Fix-timeout
Open

fix: prevent infinite hang on package loading when NCSI is stale#5128
Zeroes1 wants to merge 1 commit into
Devolutions:mainfrom
Zeroes1:Fix-timeout

Conversation

@Zeroes1

@Zeroes1 Zeroes1 commented Jul 17, 2026

Copy link
Copy Markdown

Add 30s timeout and HTTP fallback to internet connectivity check.

Problem: UniGetUI hangs indefinitely (20+ minutes) on the "Loading packages" screen when scanning installed packages. The root cause is _waitForInternetConnection() which uses NetworkInformation.GetInternetConnectionProfile() (NCSI) to check connectivity. On Windows 10, NCSI frequently returns null or NoInternetAccess even when the internet is actually working (known NCSI bug). The function has no timeout, causing an infinite loop.

Fix (Tools.cs:_waitForInternetConnection):

Added a 30-second timeout. After the timeout expires, the function logs a warning and proceeds — it no longer blocks package loading indefinitely.
Added an HTTP fallback: a HEAD request to http://msftconnecttest.com/connecttest.txt with a 5-second timeout. If NCSI incorrectly reports "no internet" (common Win10 bug) but the HTTP request succeeds, the connection is considered available.
Replaced the infinite while loop with a bounded for loop with a maximum iteration count.

close #3669

@GabrielDuf

Copy link
Copy Markdown
Contributor

Hi Zeroes1,
There are a few warnings because WebRequest.Create(string) is now obsolete. Could you please take a look?

Screenshot 2026-07-17 at 2 24 16 PM

@Kobi-Blade

Kobi-Blade commented Jul 19, 2026

Copy link
Copy Markdown

Hi Zeroes1, There are a few warnings because WebRequest.Create(string) is now obsolete. Could you please take a look?

Screenshot 2026-07-17 at 2 24 16 PM

Hi Gabriel, if you look into this, you can simplify the entire method massively using HttpClient. It is cross-platform and would fix the warnings.

public static async Task WaitForInternetConnectionAsync(
    int retryDelayMs = 1000,
    int maxRetries = 300
)
{
    if (Settings.Get(Settings.K.DisableWaitForInternetConnection))
        return;

    Logger.Debug("Checking for internet connectivity...");
    bool warned = false;

    using HttpClient client = new HttpClient
    {
        Timeout = TimeSpan.FromSeconds(3)
    };

    for (int attempt = 0; attempt < maxRetries; attempt++)
    {
        try
        {
            using var response = await client.SendAsync(
                new HttpRequestMessage(HttpMethod.Head, "http://connectivitycheck.gstatic.com/generate_204"),
                HttpCompletionOption.ResponseHeadersRead
            );

            if (response.IsSuccessStatusCode)
            {
                Logger.Debug("Internet connectivity was established.");
                return;
            }
        }
        catch
        {

        }

        if (!warned)
        {
            Logger.Warn(
                "User is not connected to the internet, waiting for an internet connection to be available..."
            );
            warned = true;
        }

        await Task.Delay(retryDelayMs);
    }

    Logger.Error("Internet connection could not be established within the allowed time.");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] UnigetUI can't load all list of software?

3 participants