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

Move downloads outside of gui transaction #2073

Merged

Conversation

archer884
Copy link
Contributor

#1935 mentions a timeout exception impacting only the GUI on large and/or slow downloads (taking longer than ten minutes). I believe this can be solved by moving the download process outside of the transaction begun in the GUI (there are additional transactions started inside Core which are not impacted by download times).

Of course, this is a terrible idea if changes to the cache are intended to be covered by the transaction, but I have not dug into the cache code deeply enough to know if this is the case. Thoughts?

To minimize the changes required (and thereby maximize my odds of not breaking anything), I have created the new download workflow in addition to the old one rather than replacing the old one. This is largely because the old one is in use in lots of different places throughout the GUI code--for additions and updates as well as bulk installs. This PR pretty much just overhauls bulk installs, since they exhibited the problem for me when I tried to update for 1.3 the other day.

I have just used a build based on this to update my KSP install, so it works. On my machine. We all know what that's worth, surely. :)

First PR here. If I have goofed on anything, I apologize.

@archer884
Copy link
Contributor Author

Cleaning out PR list.

@archer884 archer884 closed this Aug 3, 2017
@politas
Copy link
Member

politas commented Aug 11, 2017

The concept seems sound to me. I don't have a good understanding of that section of the code.

@archer884
Copy link
Contributor Author

@politas It's been awhile since I looked, but, from memory...

Basically, a transaction is begun as soon as install is initiated, and during that transaction (which has a 10 minute maximum timeout) we have to download and install all the mods. This usually isn't a problem, but several things can then cause the transaction to time out: lots of mods, a single mod with a large download, or a single download from a slow-ass server.

This patch causes the download process to take place before the transaction is actually started. As noted above, this risks causing changes to the download cache not to be covered by the transaction, but I don't know if the download cache is meant to be covered; I kind of just assumed it's not.

@politas
Copy link
Member

politas commented Aug 17, 2017

The only issue I can see is an incomplete download getting cached and poisoning further attempts?

@archer884
Copy link
Contributor Author

@politas So the download cache is transacted?

@politas
Copy link
Member

politas commented Aug 17, 2017

I believe we add any successful downloads to the cache regardless of the transaction success, and it looks like Core/Net/NetAsyncModulesDownloader method ModuleDownloadsComplete only adds completed downloads to the cache, so taking the downloads out of the transaction should be ok. I note that you tested this successfully; what platform do you use?

@politas politas reopened this Aug 17, 2017
@archer884
Copy link
Contributor Author

archer884 commented Aug 17, 2017 via email

//
// JObject obj = JObject.Parse(json);
// return obj.IsValid(metadata_schema);
license = license ?? new List<License> { License.UnknownLicense };
Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly, this sets licence to "unknown" if it doesn't match anything in the licence list? We would generally prefer a failure (this code is mainly intended for netkan)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@politas The old code would create a new instance of an unknown license in that case, on line 367. The new code does the same thing but uses the static License.UnknownLicense instead of a new instance. I probably shouldn't have been doing arbitrary little cleanup-y things like that in a branch about timeouts, but the effect (creating the unknown license) is not changed.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. The little code cleanups are making it hard to review, given my poor understanding of the transaction code!

@archer884 archer884 force-pushed the fix/download-outside-gui-transaction branch from ea14a4e to 0d38529 Compare August 23, 2017 19:34
@archer884
Copy link
Contributor Author

@politas I have categorized the work into different commits based on what it actually does. I hope that will make this easier to review. In theory, it should also make it easier to cherry-pick only the parts of the work you want at the moment, if you prefer to go that route.

@@ -96,6 +97,31 @@ public partial class Main
installCanceled = true;
};

GUI.user.RaiseMessage("About to install...\r\n");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that sucks. I'll poke that when I get home and see if I can understand what's going on.

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, I deleted this comment from the commit in order to move it to the PR:
"This message is appearing when the only actions are removing mods, and the client seems to get stuck after that."

Copy link
Member

Choose a reason for hiding this comment

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

I haven't tested updates, but I suspect they may have the same problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't made any updates; I just rearranged the pull request to be easier to review. I didn't get to leave my day job yesterday until dark thirty. :(

Copy link
Member

@politas politas Aug 25, 2017

Choose a reason for hiding this comment

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

Sorry, I meant "I haven't tested running a changeset that only contains updates to installed mods, but I suspect it would suffer the same problem"

This change simplifies the `DeserializationFixes` method. Fom what Visual Studio is telling me right now, that method isn't actually used to begin with, so maybe we'd be better off deleting it--but I'm on a mac right now, so I wouldn't take my word for it.
This class allows us to move the module resolution and download process outside the GUI transaction by permitting us to treat both cached and uncached modules equivalently during the lead up to that process.
@archer884 archer884 force-pushed the fix/download-outside-gui-transaction branch from 0d38529 to b2cfe5f Compare August 25, 2017 01:16
Here we use the new ModuleResolution class to perform the work of downloading uncached modules before initiating the GUI transaction wrapping the install process.
@archer884 archer884 force-pushed the fix/download-outside-gui-transaction branch from b2cfe5f to 565269c Compare August 25, 2017 01:25
@archer884
Copy link
Contributor Author

@politas If you look at the EnsureCache method on line 259 of ModuleInstaller.cs, you'll see where where it accepts a downloader that defaults to null. That method was throwing a null exception in the event that there was nothing to download (and, hence, no downloader was being created).

It now just aborts if there's nothing to download.

@politas
Copy link
Member

politas commented Aug 25, 2017

@archer884 , is there a new commit you need to push up to GitHub for that fix?

@archer884
Copy link
Contributor Author

@politas No, the change is already in here. What I did is that I took this opportunity to rebase on master, pull in all the latest changes from there, and then update my previous commit with the corrected code.

@politas
Copy link
Member

politas commented Aug 25, 2017

That seems to have fixed up that issue. Thanks for the reorg, makes it much clearer!

@politas
Copy link
Member

politas commented Aug 25, 2017

Now we just need to work out why Jenkins is complaining. @techman83, can you have a look if you've got a minute? Might be more @dbent's sphere of expertise, though.

@techman83
Copy link
Member

Looks like just a transient issue connecting to the mono repos. I've restarted the build, it'll probably be fine now.

@politas
Copy link
Member

politas commented Aug 26, 2017

Ah, beautiful. Merging!

@politas politas merged commit 565269c into KSP-CKAN:master Aug 26, 2017
@archer884 archer884 deleted the fix/download-outside-gui-transaction branch August 28, 2017 15:29
WKFO added a commit to WKFO/CKAN that referenced this pull request Sep 8, 2017
* License cleanup

This change simplifies the `DeserializationFixes` method. Fom what Visual Studio is telling me right now, that method isn't actually used to begin with, so maybe we'd be better off deleting it--but I'm on a mac right now, so I wouldn't take my word for it.

* Remove unused code

* Cleanup usings

* Whitespace cleanup

* Add ModuleResolution class

This class allows us to move the module resolution and download process outside the GUI transaction by permitting us to treat both cached and uncached modules equivalently during the lead up to that process.

* Move download outside GUI transaction

Here we use the new ModuleResolution class to perform the work of downloading uncached modules before initiating the GUI transaction wrapping the install process.

* Merge KSP-CKAN#2073 Move downloads outside of gui transaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants