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

Threading problem, locks other instance files #90

Closed
tomasr78 opened this issue Sep 27, 2021 · 6 comments
Closed

Threading problem, locks other instance files #90

tomasr78 opened this issue Sep 27, 2021 · 6 comments

Comments

@tomasr78
Copy link

tomasr78 commented Sep 27, 2021

I have found a lock file issue with MedallionShell when it is running several threads.

For example, I run two command-line applications (App1, App2) using the code below and pass two different files for each app (App1 -> File1, App2 -> File2)

Sometimes, the App1 -> File1 finish processing the file, but for an unknown reason, File1 is locked by the App2 app.
It is not possible to read the File1 file until App2 exits, through File1 was executed with App1 app in the first Command.Run instance.

Any idea what is going on? Is the code below thread-safe?

 var command = Command.Run(MyApp,
                    new[] {MyFile},
                    options => options
                        .Timeout(new TimeSpan(0, 0, 0, Conversion.Timeout))
                        .CancellationToken(Conversion.CancellationToken));

                try
                {
                    command.Wait();
                }
                catch (TimeoutException)
                {
                    throw new MyException(...);
                }

                if (!command.Result.Success)
                    switch (command.Result.ExitCode)
                    {
                        //Report exception
                    }
@tomasr78
Copy link
Author

tomasr78 commented Oct 5, 2021

I have found that this problem exists when UseShellExecute is set to False.

@madelson
Copy link
Owner

madelson commented Oct 6, 2021

Hi @tomasr78 it's going to be hard to figure out more without more information. For example:

  • What are App1 and App2? A known program or something you wrote? What do they each do?
  • Can you show the full code that kicks off both commands? The code shown kicks off 1 command
  • What happens if you use Process rather than MedallionShell?

This seems unlikely to be a MedallionShell issue because in the code shown MedallionShell doesn't touch the file at all; it just passes the name of the file as a command line argument.

@tomasr78
Copy link
Author

Sorry for the confusion, the problem is related to Magick.NET library which uses CreateProcess under the hood to run ImageMagick. It seems their CreateProcess interacts with other CraeteProcess methods and produce file lock problems.
The problem described here dlemstra/Magick.NET#1054

@madelson
Copy link
Owner

@tomasr78 thanks for the update. Do you think this issue can be closed?

@tomasr78
Copy link
Author

The issue is related to handles inheritance if you are not yet familiar with the problem you can read more at dotnet/runtime#13943

Do you have any plans to improve your library to fix the issue?

@madelson
Copy link
Owner

@tomasr78 I've had #54 filed for some time.

The problem is that AFAIK there's not really any way to do that without abandoning the Process class entirely and reimplementing everything using P/Invoke (let me know if you disagree).

Thus far, I've been waiting for .NET to offer a solution which MedallionShell can then adopt.

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

No branches or pull requests

2 participants