Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fresh WebClient for fallback URLs #2539

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

HebaruSan
Copy link
Member

Problem

Sometimes when downloading mods, CKAN indicates negative bytes remaining and greater than 100% progress towards completion. This problem has been reported on both CmdLine and GUI, and presumably ConsoleUI would be affected as well:

image

image

Cause

When the primary download URL for a redistributable mod fails, we fall back to its archive.org URL as of #2284. This is done by calling agent.DownloadFileAsync in the agent.DownloadFileCompleted event handler when it indicates failure. Notably this re-uses the same WebClient object.

Since the negative bytes remaining and greater than 100% progress numbers come directly from values provided by WebClient, I think the WebClient object is getting corrupted by this sequence of events. It may not be prepared for us to initiate a new download while the previous one is still being dealt with.

Changes

NetAsyncDownloaderDownloadPart'sWebClient object is now changed from public to private. Small wrapper functions and events are added to handle the operations that this object performs, and NetAsyncDownloader is updated to call them:

  • Download - Replaces agent.DownloadFileAsync
  • Abort - Replaces agent.CancelAsync
  • Progress - Replaces agent.DownloadProgressChanged
  • Done - Replaces agent.DownloadFileCompleted

This encapsulation allows NetAsyncDownloaderDownloadPart.Download to ensure that its WebClient object is replaced and re-initialized before any download operation. Rather than re-using a potentially scrambled object, fallback URLs will now have their own fresh WebClient.

Should fix #2508, but I can't make this problem happen on demand so testing is inconclusive.

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Pull request Mono Issues specific for Mono Network Issues affecting internet connections of CKAN labels Oct 15, 2018
@politas politas merged commit a308b9a into KSP-CKAN:master Oct 23, 2018
politas added a commit that referenced this pull request Oct 23, 2018
@HebaruSan HebaruSan deleted the fix/weird-progress branch October 23, 2018 14:53
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 Mono Issues specific for Mono Network Issues affecting internet connections of CKAN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CKAN Mod install larger than 100%
2 participants