neos-modding-group / NeosModLoader

A mod loader for Neos VR
GNU Lesser General Public License v3.0
61 stars 22 forks source link

Save configs synchronously on shutdown #87

Closed zkxs closed 1 year ago

zkxs commented 1 year ago

The original mod configuration implementation saved synchronously, but in #38 all config saving was switched over to a background thread. While doing some unrelated debugging I noticed that the shutdown hook saves were also asynchronous, and it struck me as incorrect and dangerous.

It's pretty typical for 10s of mods to save configs on shutdown, and I don't think there's a compelling performance benefit to doing all that IO concurrently. However, I do think there's a compelling safety benefit to doing all the saves synchronously: I believe Task.Run() uses background threads, which do not keep the managed execution environment running. In other words, there's no guarantee those background saves won't get interrupted. Doing the saves synchronously ensures they'll actually finish before Neos exits.