chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.36k stars 903 forks source link

chocolatey.config gets corrupted when multiple processes access simultaneously #1258

Closed mwallner closed 7 years ago

mwallner commented 7 years ago

What You Are Seeing?

Broken chocolatey.config after two processes use choco.exe at the same time. (sometimes)

<?xml version="1.0" encoding="utf-8"?>
<chocolatey xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <containsLegacyPackageInstalls>false</containsLegacyPackageInstalls>
  <commandExecutionTimeoutSeconds>0</commandExecutionTimeoutSeconds>
  <config>
    <add key="cacheLocation" value="" description="Cache location if not TEMP folder." />
    <add key="containsLegacyPackageInstalls" value="true" description="Install has packages installed prior to 0.9.9 series." />
    <add key="commandExecutionTimeoutSeconds" value="2700" description="Default timeout for command execution." />
    <add key="

What is Expected?

config shouldn't be corrupted

How Did You Get This To Happen? (Steps to Reproduce)

Two processes -> both use choco.exe at the very same time (choco list is sufficient)

This Issue is a follow-up of GH-1047

Apteryx0 commented 7 years ago

This is probably related to GH-653, specifically this change may help (but probably won't eliminate all possible corruption - but at the very least it relies on the OS copy being atomic...)

diff --git a/src/chocolatey/infrastructure/services/XmlService.cs b/src/chocolatey/infrastructure/services/XmlService.cs
index 00619f6..032e87d 100644
--- a/src/chocolatey/infrastructure/services/XmlService.cs
+++ b/src/chocolatey/infrastructure/services/XmlService.cs
@@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.services
     using System.Text;
     using System.Xml;
     using System.Xml.Serialization;
+    using System.Diagnostics;
     using cryptography;
     using filesystem;
     using tolerance;
@@ -65,7 +66,7 @@ namespace chocolatey.infrastructure.services
         {
             _fileSystem.create_directory_if_not_exists(_fileSystem.get_directory_name(xmlFilePath));

-            var xmlUpdateFilePath = xmlFilePath + ".update";
+            var xmlUpdateFilePath = xmlFilePath + ".update" + Process.GetCurrentProcess().Id().ToString();

             FaultTolerance.try_catch_with_logging_exception(
                 () =>
ferventcoder commented 7 years ago

We'll close the other as a duplicate of this.

Apteryx0 commented 7 years ago

FWIW, I'm put the above change (well, the 0.10.5 version of it - the one above was for 0.10.3) into our local chocolatey build and I'll see over the next couple of weeks if the issue reproduces or not.....

ferventcoder commented 7 years ago

Fixed for 0.10.6

FLeven commented 2 years ago

I had the same error on version 12.1.

Error deserializing response of type chocolatey.infrastructure.app.configuration.ConfigFileSettings: Fehler im XML-Dokument (22,14). This is try 1/3. Retrying after 400 milliseconds. Error converted to warning: Fehler im XML-Dokument (22,14).

renamed the config file, renamed the config.backup file and it is working again.