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

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

Closed
mwallner opened this issue Apr 20, 2017 · 7 comments
Closed

Comments

@mwallner
Copy link
Member

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
Copy link

Apteryx0 commented May 1, 2017

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 ferventcoder self-assigned this May 1, 2017
@ferventcoder
Copy link
Member

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

@Apteryx0
Copy link

Apteryx0 commented May 2, 2017

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
Copy link
Member

Fixed for 0.10.6

ferventcoder pushed a commit that referenced this issue May 29, 2017
Previously, multiple Chocolatey processes running could affect or
corrupt the chocolatey.config file depending on how they accessed the
file. Implement a single global mutex (process-wide) on serialization and
deserialization of the xml configuration file to ensure the file stays
consistent.
ferventcoder added a commit that referenced this issue May 29, 2017
Add logging and xml docs to public items
ferventcoder added a commit that referenced this issue May 29, 2017
A named mutex cannot be used in mono, it causes errors. If choco is not
being run on Windows, skip the named mutex and just allow the function
/ action to execute.
ferventcoder added a commit that referenced this issue May 29, 2017
Give the MUTEX_TIMEOUT 2 seconds, but also increase the retries by
waiting 200 milliseconds and increasing by 200 milliseconds between
retries.
@FLeven
Copy link

FLeven commented Mar 4, 2022

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.

@FLeven
Copy link

FLeven commented Dec 17, 2024

I still get the same error on Chocolatey v2.4.1 Business.

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.backup file and it is working again.

@pauby
Copy link
Member

pauby commented Dec 17, 2024

@FLeven this issue is closed. As a Chocolatey for Business customer, can you please raise a support ticket? You can find your options for doing so by running choco support.

@chocolatey chocolatey locked as resolved and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants