Azure / azure-iot-protocol-gateway

Azure IoT protocol gateway enables protocol translation for Azure IoT Hub
Other
225 stars 152 forks source link

IothubClient ReceiveAsync() timed out #133

Open hauszerm opened 5 years ago

hauszerm commented 5 years ago

We have upgraded the protocol gateway After the Upgrade we have an issue with the IothubClient.ReceiveAsync() method.

Code Snippet

   async void Receive() 
    {
       Message message = null;
        IByteBuffer messagePayload = null;
        try
        {
            while (true)
            {
                message = await this.deviceClient.ReceiveAsync(TimeSpan.MaxValue);
                if (message == null)
                {
                    this.messagingChannel.Close(null);
                    return;
                }
               .......

We are now receiving NULL messages after 40s - 60s. Before the Update, the ReceiveAsync() delivered a NULL message only in case of an iothub disconnect, not every 40s - 60s. According to the unchanges code in this code snippet, the connection to the iothub will be closed and has to be established once more, a behaviour, which is new since the upgrade the protocol gateway SDK. Do you have any explanation for this behaviour?

best regards Michael

anhashia commented 5 years ago

@hauszerm : Unable to reproduce the issue with latest version of C# device SDK 1.20.0 which was recently released.

Used following code snippet in a standalone application

 while (true)
  {

            using (DeviceClient mydeviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString, deviceId, TransportType.Amqp_Tcp_Only))
            {
                receivedMessage = await mydeviceClient.ReceiveAsync(TimeSpan.MaxValue).ConfigureAwait(false);

   if (receivedMessage != null)
                    {
                        messageData = Encoding.ASCII.GetString(receivedMessage.GetBytes());
                        Console.WriteLine("\t{0}> Received message: {1}", DateTime.Now.ToLocalTime(), messageData);

I don't see any NULL messages after 40s - 60 seconds. Are you able to reproduce the issue using a standalone application ?