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

Calling Direct Method issue with the auto-generated code on VSCode #480

Closed
ewertons opened this issue Jul 16, 2019 · 3 comments
Closed

Calling Direct Method issue with the auto-generated code on VSCode #480

ewertons opened this issue Jul 16, 2019 · 3 comments
Assignees

Comments

@ewertons
Copy link

This issue was filed incorrectly under https://github.com/Azure/azure-iot-sdk-csharp
Moving it to the correct repository on behalf of @SONENU
Original issue: Azure/azure-iot-sdk-csharp#980


  • OS, version, SKU and CPU architecture used:
  • Application's .NET Target Framework :
  • Device:
  • SDK version used:

Description of the issue:

[Calling Direct Method Issue]
After several days of investigation and effort. I've found that when I am implementing IoT Edge Module by command-line in VSCode, calling Direct Method failed with an auto-generated code as below on VSCode. I had to change the code the other way to make it run properly. What they are different and what's MS's opinion.

The environment we use currently and see some similar issues below.
IoT Edge version 1.0.7.1: https://github.com/Azure/azure-iotedge/releases
• Fixes ObjectDisposedException (that we've seen also in our logs so it might be good to update the deployments to this version already)

IoT SDK C# version 1.20.2: https://github.com/Azure/azure-iot-sdk-csharp/releases
• It's probably better to have the SDK updated to the latest release and start fixing the version instead of using 1.* which automatically uses the latest version at build time, which means we are not in control of the version we will get during the build.

Github reported issues similar to what we're seeing:
• Issue #551: Azure/azure-iot-sdk-csharp#571
• Issue #646: Azure/iotedge#646

Code sample exhibiting the issue:

class Program
{
static async Task Main(string[] args)
{

        // Wait until the app unloads or is cancelled
        var cts = new CancellationTokenSource();
        AssemblyLoadContext.Default.Unloading += (ctx) => cts.Cancel();
        Console.CancelKeyPress += (sender, cpe) => cts.Cancel();
        //WhenCancelled(cts.Token).Wait();//Auto generated code when creating new module
        await WhenCancelled(cts.Token);//Success with this code
    }

Console log of the issue:

[DirectMethod] Failed to invoke Direct Method: Error: {"Message":"{"errorCode":504101,"trackingId":"8fb95f15eb734f5d92c292dc5fc29e17-G:19-TimeStamp:06/18/2019 10:07:22-G:11-TimeStamp:06/18/2019 10:07:22","message":"Timed out waiting for the response from device.","info":{},"timestampUtc":"2019-06-18T10:07:22.3918499Z"}","ExceptionMessage":""}

@ewertons
Copy link
Author

For details of the initial conversation please refer to Azure/azure-iot-sdk-csharp#980

@blackchoey
Copy link
Contributor

blackchoey commented Jul 17, 2019

@SONENU Sorry for the delayed response. I tried the sample code updated by you, but haven't met the timeout issue yet. Could you share steps about how you ran into the timeout issue? Here's the steps performed by me:

  1. Update the main function to the source block in your comment "You can reproduce this with this source block below."
  2. Right click the deployment.template.json and choose Build and Run IoT Edge Solution in Simulator
  3. Using Azure IoT Hub Toolkit extension, find the IoT Edge device used by simulator. Expand Modules of the device and right click SampleModule, choose Invoke Module Direct Method
  4. Fill method name SetTelemetryInterval and a random int value in the input boxes. Invoke the direct method
  5. Check the output of Azure IoT Hub Toolkit extension, I can see the response the direct method is status 200.
  6. Check the logs of SampleModule in simulator, I can see there're messages "Telemetry interval set to xxx seconds"

By the way, I noticed you modified the main function to static **async Task** Main in you sample that causes the deadlock issue. Though I haven't repro the issue, it's recommended to use await if you want to declare an async function to avoid possible deadlocks. The main function in our template is a synchronized function (static void Main), that's why we uses .Wait() in the main function. Hope this helps with your problem. Please let us know if you have additional questions.

@blackchoey
Copy link
Contributor

@SONENU As mentioned above, if you would like to declare the main function as async, it's recommended to use the await to avoid possible deadlocks. We haven't heard you for a while about whether this recommendation resolves your question. I'm going to close this issue for now and feel free to open new issues if you have additional questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants