Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.37k stars 4.79k forks source link

[BUG] DeviceClient staying open after CloseAsync #24550

Closed PaintedGauthier closed 3 years ago

PaintedGauthier commented 3 years ago

Describe the bug Opening and closing (async) a device client, in a using statement never shuts down properly.

Expected behavior DotNetty.Common.Concurrency.SingleThreadEventExecutor.PollTask threads stop, and program exits

Actual behavior (include Exception or Stack Trace) Program does not exit, 8 DotNetty.Common.Concurrency.SingleThreadEventExecutor.PollTask threads run pretty much forever

To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)

  1. .net console app, 4.8
  2. install nuget package "Microsoft.Azuer.Devices.Client" 1.38.0
  3. run console, for however long or short you want
  4. type anything, hit enter
  5. program never exits
        class Program
    {
            private static string _connection_string = $"HostName={url};DeviceId={the_id};SharedAccesskey={key}";// fill your in
        public static bool is_running = false;
        static void Main(string[] args)
        {

            is_running = true;
            new System.Threading.Thread(new System.Threading.ThreadStart(thread_method)).Start();
            Console.WriteLine("enter to exit");
            String line = Console.ReadLine();
            is_running = false;
        }
        public static async void thread_method()
        {
            using (var _deviceClient = DeviceClient.CreateFromConnectionString(_connection_string, TransportType.Mqtt))
            {
                await _deviceClient.OpenAsync();
                while (is_running) System.Threading.Thread.Sleep(500);
                await _deviceClient.CloseAsync();
            }
            }
}

Environment:

jsquire commented 3 years ago

This issue has been transferred to the repository where the Microsoft.Azure.Devices.Client library is maintained as #2194.