Skip to content

Don't close 416 responses on dotnet#4646

Merged
HebaruSan merged 8 commits into
KSP-CKAN:masterfrom
HebaruSan:fix/disposed-webresponse-exception
May 26, 2026
Merged

Don't close 416 responses on dotnet#4646
HebaruSan merged 8 commits into
KSP-CKAN:masterfrom
HebaruSan:fix/disposed-webresponse-exception

Conversation

@HebaruSan

@HebaruSan HebaruSan commented May 26, 2026

Copy link
Copy Markdown
Member

Problems

  • If the in-progressdownloading folder of the cache contains a completed download for a module, trying to install it throws an exception on the net10 build:
    System.Net.WebException: An exception occurred during a WebClient request.
     ---> System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'System.Net.HttpWebResponse'.
       at System.Net.HttpWebResponse.GetResponseStream()
       at System.Net.WebClient.<>c__DisplayClass160_0.<OpenReadAsync>b__0(IAsyncResult iar)
       --- End of inner exception stack trace ---
       at CKAN.NetAsyncModulesDownloader.DownloadModules(IEnumerable`1 modules) in C:\Users\user\github\CKAN\Core\Net\NetAsyncModulesDownloader.cs:line 111
       at CKAN.NetAsyncModulesDownloader.<>c__DisplayClass21_0.<DownloadsCollection>b__1() in C:\Users\user\github\CKAN\Core\Net\NetAsyncModulesDownloader.cs:line 166
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location ---
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location ---
       at CKAN.NetAsyncModulesDownloader.<>c__DisplayClass21_0.<DownloadsCollection>b__2(Task t) in C:\Users\user\github\CKAN\Core\Net\NetAsyncModulesDownloader.cs:line 173
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location ---
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location ---
       at CKAN.NetAsyncModulesDownloader.ModulesAsTheyFinish(IReadOnlyCollection`1 cached, Task dlTask, BlockingCollection`1 blockingQueue)+MoveNext() in C:\Users\user\github\CKAN\Core\Net\NetAsyncModulesDownloader.cs:line 157
       at CKAN.IO.ModuleInstaller.ModsInDependencyOrder(RelationshipResolver resolver, IReadOnlyCollection`1 cached, IEnumerable`1downloading)+MoveNext() in C:\Users\user\github\CKAN\Core\IO\ModuleInstaller.cs:line 203
       at CKAN.IO.ModuleInstaller.AddRemove(HashSet`1& possibleConfigOnlyDirs, RegistryManager registry_manager, RelationshipResolver resolver, IReadOnlyCollection`1 add, ISet`1 autoInstalled, IReadOnlyCollection`1 remove, IDownloader downloader, Boolean enforceConsistency, InstalledFilesDeduplicator deduper) in C:\Users\user\github\CKAN\Core\IO\ModuleInstaller.cs:line 1262
       at CKAN.IO.ModuleInstaller.Upgrade(IReadOnlyCollection`1& modules, IDownloader downloader, HashSet`1& possibleConfigOnlyDirs, RegistryManager registry_manager, InstalledFilesDeduplicator deduper, ISet`1 autoInstalled, ISet`1 skipFiles, Boolean enforceConsistency, Boolean ConfirmPrompt) in C:\Users\user\github\CKAN\Core\IO\ModuleInstaller.cs:line 1461
    
  • A user shared a screenshot with light file and folder icons on a white background:
    image
  • The tab controls in light mode look different from how they did in previous releases, unintentionally

Causes

  • When the in-progress download file is already completed, the server responds with a 416 status, in response to which we close the response. I think this was a workaround for Mono that also didn't break on Windows at the time, but it does in net10. There must have been some implementation changes to WebClient that make it attempt to access the response when it did not in net481.
  • Util.DarkMode previously checked only that we were running on Windows and that the registry key was set. Unfortunately, the WinForms dark mode does not work on Windows 10 even if the registry key is set, so Util.DarkMode was returning true despite the colors being light mode, which caused the colors of the file and folder icons to be inverted.
  • ThemedTabControl turned off owner drawing for all net10 clients, even if dark mod was not active

Changes

  • Now we only close a 416 response on net481, not on net10.
    Tests are included to exercise this.
    Fixes [Bug]: Cannot access a disposed object 'System.Net.HttpWebResponse' #4572.
  • The failed downloads dialog is updated to display the full stack trace for exceptions that aren't Krakens or IOExceptions or WebExceptions, to make such issues easier to investigate
  • Now Util.DarkMode checks for Windows 11, so the icons will not be inverted on Windows 10
  • Now ThemedTabControl uses owner drawing for light mode, so the tabs will look as they did in previous releases

@HebaruSan HebaruSan added Bug Something is not working as intended GUI Issues affecting the interactive GUI Core (ckan.dll) Issues affecting the core part of CKAN Network Issues affecting internet connections of CKAN labels May 26, 2026
@HebaruSan HebaruSan force-pushed the fix/disposed-webresponse-exception branch from 6bdaa65 to 92beb25 Compare May 26, 2026 22:53
@coveralls

This comment was marked as off-topic.

@HebaruSan HebaruSan merged commit 46ea0da into KSP-CKAN:master May 26, 2026
9 checks passed
@HebaruSan HebaruSan deleted the fix/disposed-webresponse-exception branch May 26, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN GUI Issues affecting the interactive GUI Network Issues affecting internet connections of CKAN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot access a disposed object 'System.Net.HttpWebResponse'

2 participants