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

Latest device client does not connect over MQTT #3413

Closed
WillooWisp opened this issue Dec 19, 2023 · 12 comments
Closed

Latest device client does not connect over MQTT #3413

WillooWisp opened this issue Dec 19, 2023 · 12 comments
Labels
bug Something isn't working. investigation-required Requires further investigation to root cause this. IoTSDK Tracks all IoT SDK issues across the board

Comments

@WillooWisp
Copy link

Upgrading from the release in 2023-05-01 with Microsoft.Azure.Devices.Client 1.42.0 to 2023-12-11 and Microsoft.Azure.Devices.Client 1.42.1 using MQTT, causes the device client to never connect and thus calls to SetReceiveMessageHandlerAsync fails. Downgrading again without any code changes whatsoever makes it work again as expected.

var transportType = TransportType.Mqtt_Tcp_Only;
string deviceConnectionString = $"HostName={iotHubUri};DeviceId={DeviceId};SharedAccessKey={primaryKey}";
var options = new ClientOptions
{
    SdkAssignsMessageId = SdkAssignsMessageId.WhenUnset,
};

var deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, transportType, options);

deviceClient.SetConnectionStatusChangesHandler(OnConnnectionStatusChanges);

await deviceClient.SetReceiveMessageHandlerAsync(OnMessageReceivedAsync, null);
@WillooWisp WillooWisp added the bug Something isn't working. label Dec 19, 2023
@github-actions github-actions bot added the IoTSDK Tracks all IoT SDK issues across the board label Dec 19, 2023
@timtay-microsoft
Copy link
Member

Can you share some details about what .NET framework you are using in this application? .NET 6+? And what OS are you running here?

@timtay-microsoft timtay-microsoft added the customer-input-needed Issue lacks enough data for a proper investigation. label Dec 19, 2023
@WillooWisp
Copy link
Author

I'm using .NET 8 and Windows 11.

@timtay-microsoft
Copy link
Member

We don't currently support running this SDK on .NET 8, but we'll try to look into this when we get the chance. In the meantime, targeting .NET 7 should fix this issue for you.

@WillooWisp
Copy link
Author

Why do you think. NET 8 is the cause of this when the previous version works fine with. NET 8?

@timtay-microsoft
Copy link
Member

The only meaningful change from the previous SDK version is the upgrade we made to DotNetty from 0.7.4 to 0.7.5. Given that you are seeing this problem (only?) when using MQTT, that suggests to me that there may be some new compatibility issue between DotNetty and .NET 8 in DotNetty 0.7.5

@timtay-microsoft timtay-microsoft added investigation-required Requires further investigation to root cause this. and removed customer-input-needed Issue lacks enough data for a proper investigation. labels Dec 25, 2023
@Clockwork-Muse
Copy link

I think I'm hitting this as well, running in a .Net8 Jammy devcontainer. I'm actually attempting to use mosquitto as a test MQTT broker, so that I don't need developers to register devices to an actual Azure IoT Hub and interfere with each other (among other benefits). Under .Net8 it would just... hang when attempting to connect, whereas on .Net7 it will connect and start passing messages.

@rido-min
Copy link
Member

rido-min commented Jan 3, 2024

I believe this issue is related to the lack of .NET8 support in dotnetty Azure/DotNetty#614

@nivalxer
Copy link

nivalxer commented Jan 4, 2024

The reason is that the logic for the SSLStream read buffer has been changed in .NET 8. DotNetty needs to be updated accordingly. I have submitted a pull request (PR), but I am uncertain how long it will take to be merged.
Azure/DotNetty#616

@jonmikeli
Copy link

Similar issues with DPS (provisioning) after the last upgrade.
Context:

  • .NET 8 (no way to go back to .NET 7, it is not LTS)
  • Security type: SAS
  • Enrollment type: Group

@codeputer
Copy link

Still waiting for this to be fixed? Is this not a urgent and necessary to restore faith in latest Nuget packages?

@jenscski
Copy link

I think this is fixed in DotNetty now, add direct references to DoNetty in your code to use latest

<PackageReference Include="DotNetty.Codecs.Mqtt" Version="0.7.6" />
<PackageReference Include="DotNetty.Handlers" Version="0.7.6" />

@andyk-ms
Copy link
Contributor

andyk-ms commented Apr 3, 2024

Should be addressed in the new release:
https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/2024-03-28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. investigation-required Requires further investigation to root cause this. IoTSDK Tracks all IoT SDK issues across the board
Projects
None yet
Development

No branches or pull requests

9 participants