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

[BUG] DeviceClient staying open after CloseAsync #2194

Closed
jsquire opened this issue Oct 7, 2021 · 5 comments
Closed

[BUG] DeviceClient staying open after CloseAsync #2194

jsquire opened this issue Oct 7, 2021 · 5 comments
Assignees
Labels
fix-checked-in Fix checked into main or preview, but not yet released. IoTSDK Tracks all IoT SDK issues across the board question Further information is requested.

Comments

@jsquire
Copy link
Member

jsquire commented Oct 7, 2021

Issue Transfer

This issue has been transferred from the Azure SDK for .NET repository, #24550.

Please be aware that @PaintedGauthier is the author of the original issue and include them for any questions or replies.

Details

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:

  • Name and version of the Library package used: "Microsoft.Azuer.Devices.Client" 1.38.0
  • Hosting platform or OS and .NET runtime version:

Windows 10

Target Framework 4.8

Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • IDE and version : Visual Studio 16.11.2
@jsquire jsquire added the question Further information is requested. label Oct 7, 2021
@github-actions github-actions bot added the IoTSDK Tracks all IoT SDK issues across the board label Oct 7, 2021
@jamdavi jamdavi self-assigned this Oct 8, 2021
@luiscantero
Copy link

+1 we are affected by this bug as well. Also happens with the ModuleClient. CC @MaidaB

@jamdavi
Copy link
Member

jamdavi commented Dec 8, 2021

Just an update for all who might be looking at this. We tracked the issue down to a change with DotNetty. The following PR has been merged and we will take a new version of DotNetty to fix.

Azure/DotNetty#570

@ldeluigi
Copy link

ldeluigi commented Jan 5, 2022

News?

Seems fixed in the current version

@jamdavi
Copy link
Member

jamdavi commented Jan 10, 2022

We had been waiting on a release from the Netty team and discussed internally the best way to handle the update. The Netty team created a new version of the Common library and we are now taking a dependency on this new version of the library.

This is not required once we release the new SDK but if you want to test this out you can also take a dependency on the latest version of DotNetty.Common and it should replace the assembly at build time.

Note, if you're targeting .NET Full framework such as net472 you'll have to use a binding redirect in your app.config. Visual Studio has an option to generate one automatically.

@jamdavi jamdavi added the fix-checked-in Fix checked into main or preview, but not yet released. label Jan 11, 2022
@jamdavi
Copy link
Member

jamdavi commented Jan 31, 2022

This is now fixed with version 1.40.0 [https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/2022_01_26].

@jamdavi jamdavi closed this as completed Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix-checked-in Fix checked into main or preview, but not yet released. IoTSDK Tracks all IoT SDK issues across the board question Further information is requested.
Projects
None yet
Development

No branches or pull requests

4 participants