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

2.4.0-beta.81 throws an ObjectDisposedException sometimes #261

Closed
LordMike opened this issue Aug 9, 2019 · 7 comments
Closed

2.4.0-beta.81 throws an ObjectDisposedException sometimes #261

LordMike opened this issue Aug 9, 2019 · 7 comments
Assignees
Labels
bug help wanted We would be willing to take a well-written PR to help fix this.
Milestone

Comments

@LordMike
Copy link

LordMike commented Aug 9, 2019

Describe the bug

I needed Ctrl-C support, so I was happy to find that the latest beta had just gotten that feature. But now I'm seeing an ObjectDisposedException - but only when running without a debugger. While debugging, I see nothing.

To Reproduce
I've produced this program that exhibits the behavior.

using System;
using System.Threading;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Hosting;

namespace ConsoleApp1
{
    class Program
    {
        static async Task<int> Main(string[] args)
        {
            return await new HostBuilder()
                .RunCommandLineApplicationAsync<MyProgram>(args);
        }
    }

    class MyProgram
    {
        protected int OnExecute(CommandLineApplication app, CancellationToken cancellationToken)
        {
            Console.WriteLine("Entered. Waiting 10s");
            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(100);
                if (cancellationToken.IsCancellationRequested)
                {
                    Console.WriteLine("Cancelled");
                    break;
                }
            }

            Console.WriteLine("Finished");

            return 0;
        }
    }
}

Expected behavior
Program terminates without exception.

Screenshots
When cancelling
image

When running till end
image

Additional context

Stacktrace thrown.

Unhandled Exception: System.ObjectDisposedException: Safe handle has been closed
   at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at McMaster.Extensions.Hosting.CommandLine.Internal.CommandLineLifetime.<>c__DisplayClass11_0.<WaitForStartAsync>b__1(Object _, EventArgs __)
@dtsao
Copy link

dtsao commented Aug 10, 2019

I'm seeing the same issue using McMaster.Extensions.Hosting.CommandLine Version="2.4.0-beta.81"

@natemcmaster natemcmaster added this to the 2.4.0-rc milestone Aug 10, 2019
@natemcmaster natemcmaster added bug help wanted We would be willing to take a well-written PR to help fix this. labels Aug 10, 2019
@natemcmaster
Copy link
Owner

Looks like a bug. I'll take a look before I release 2.4.0-rc. I have limited free time to work on this library, so if someone else is interested in taking a look, I would happy to review and merge a PR to fix this.

@natemcmaster
Copy link
Owner

Give 2.4.0-beta.94 a try and let me know if it doesn't resolve your issue.

https://www.myget.org/feed/natemcmaster/package/nuget/McMaster.Extensions.CommandLineUtils/2.4.0-beta.94

Install-Package McMaster.Extensions.CommandLineUtils -Version 2.4.0-beta.94 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json

@natemcmaster natemcmaster self-assigned this Aug 13, 2019
@Allann
Copy link

Allann commented Aug 15, 2019

Installed v2.4.0-beta.99 and the error is gone.

@natemcmaster
Copy link
Owner

natemcmaster commented Aug 16, 2019 via email

@Allann
Copy link

Allann commented Aug 17, 2019

Thanks, I ended up doing that and installed beta 99 and I no longer see the exception during shutdown.

@natemcmaster
Copy link
Owner

Thanks for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted We would be willing to take a well-written PR to help fix this.
Projects
None yet
Development

No branches or pull requests

4 participants