Azure-Samples / azure-iot-samples-csharp

Provides a set of easy-to-understand samples for using Azure IoT Hub and Azure IoT Hub Device Provisioning Service and Azure IoT Plug and Play using C# SDK.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Device local proxy existing will null pointer exception

rezasherafat opened this issue · comments

Error reported on behalf of the customer (TS.) trying a VNC scenario using the proxy setup.

  • Windows 10 LTSB
  • Usage: TightVNC process (5901)
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Azure.Devices.Client.Transport.AmqpTransportHandler.WaitForDeviceStreamRequestAsync(CancellationToken cancellationToken)
   at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
   at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass25_0.<<WaitForDeviceStreamRequestAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.WaitForDeviceStreamRequestAsync(CancellationToken cancellationToken)
   at Microsoft.Azure.Devices.Client.InternalClient.WaitForDeviceStreamRequestAsync(CancellationToken cancellationToken)
   at Microsoft.Azure.Devices.Client.Samples.DeviceStreamSample.RunSampleAsync(Boolean acceptDeviceStreamingRequest) in C:\Temp\azure-iot-samples-csharp-master_stream\azure-iot-samples-csharp-master\iot-hub\Quickstarts\device-streams-proxy\device\DeviceStreamSample.cs:line 61
   at Microsoft.Azure.Devices.Client.Samples.DeviceStreamSample.RunSampleAsync() in C:\Temp\azure-iot-samples-csharp-master_stream\azure-iot-samples-csharp-master\iot-hub\Quickstarts\device-streams-proxy\device\DeviceStreamSample.cs:line 54
   at Microsoft.Azure.Devices.Client.Samples.Program.Main(String[] args) in C:\Temp\azure-iot-samples-csharp-master_stream\azure-iot-samples-csharp-master\iot-hub\Quickstarts\device-streams-proxy\device\Program.cs:line 76

There was an issue in the AmqpTransportHandler that could cause the nullreference exception, and it has been fixed by this commit Azure/azure-iot-sdk-csharp@40ed108 in the pending PR Azure/azure-iot-sdk-csharp#768
As soon as the PR gets approved and merged, we will have an ETA of when the code will make into the preview branch and packages.

This callstack matches the one I got below.
It is root-caused, and the fix is making its way into the preview branch. I will reply once it's there.

ex = {System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Azure.Devices.Client.Transport.AmqpTransportHandler.WaitForDeviceStreamRequestAsync(CancellationToken cancellationToken) in C:\Code\s1\azure-iot-sdk-csharp\iothub\device\src\Transport\AmqpTransportHandler.cs:line 283
   at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation) in C:\Code\s1\azure-iot-sdk-csharp\iothub\device\src\Transport\ErrorDelegatingHandler.cs:line 190
   at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass25_0.<<WaitForDeviceStreamRequestAsync>b__0>d.MoveNext() in C:\Code\s1\azure-iot-sdk-csharp\iothub\device\src\Transport\RetryDelegatingHandler.cs:line 254
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.WaitForDeviceStreamRequestAsync(CancellationToken cancellationToken) in C:\Code\s1\azure-iot-sdk-csharp\iothub\device\src\Transport\RetryDelegatingHandler.cs:line 251
   at Microsoft.Azure.Devices.Client.InternalClient.WaitForDeviceStreamRequestAsync(CancellationToken cancellationToken) in C:\Code\s1\azure-iot-sdk-csharp\iothub\device\src\InternalClient.cs:line 930
   at Microsoft.Azure.Devices.E2ETests.DeviceStreamingTests.DeviceStreaming_WaitForDeviceStreamRequestAsync_60secs_TimesOut_Amqp() in C:\Code\s1\azure-iot-sdk-csharp\e2e\test\DeviceStreamingE2ETests.cs:line 228

However, it would be good to get more details from the customer to make sure they are not hitting another issue (although improbable).

  • Which sample are they using?
  • Could we get the exact description of the steps performed by the customer (started sample X, using protocol Y, waited N seconds, hit the issue)?
  • Would it be possible for the customer to attempt the same scenario using the actual code from https://github.com/Azure/azure-iot-sdk-csharp/tree/preview? That way we could get debug bits and more precise callstacks.
  • Also there was a comment mentioning that the customer hit the same issue with other protocols. Which protocols in specific? Could we get callstacks for those too please?

Hi,

  1. We experienced the issue while running the code downloaded from the location Here

  2. This is the step I followed to replicate the issue

        a. Start the VNC process in admin mode. Remove the security required in the VNC softwares . Verify that processes are running by cross checking the port numbers and process file in the Windows resource monitor(resmon)
        b. Navigate to the location of code. Run "dotnet build" followed by dotnet run <<device connection string>>  localhost 5900
    

Waited for approximately a minute. Than the error came up on the screen.

  1. Will test using the preview branch and will update

  2. Attached are the files which has stack trace for other protocols.
    stacktrace_amqp_websocket.txt
    stacktract_amqp.txt
    stacktract_mqtt.txt
    stacktract_Mqtt_WebSocket.txt

Hi @HariharanAnantharaman,

thanks for the logs.
The AMQP and AMQP/WS logs are expected, they have a the same callstack signature for which we already have a fix for.
The MQTT ones are expected (considering you are using the sample as is, without change). As you can see here, the sample has a cancellation token with a limited timespan, so it is expected that if you don't send any device streaming requests the WaitForDeviceStreamingRequestAsync will eventually be cancelled by that token. You need to extend the sample for your project needs.

The fix for AMQP is still in the process of being merged, I will reply back as soon as we have it in.
Once again, thank you for sharing the logs!

@HariharanAnantharaman, the new preview SDK release should address the AMQP issues you reported. PR #42 is the sample should also address the cancellation token timeout you faced using MQTT protocol.

Please try again by getting the latest sample and rebuilding the project using the latest SDK. I am also closing this issue - please reopen if there are remaining issues.