Uploaded image for project: 'Qpid Proton'
  1. Qpid Proton
  2. PROTON-2044

Azure IoT Hub local-idle-timeout expired

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not A Bug
    • Affects Version/s: proton-c-0.24.0
    • Fix Version/s: None
    • Component/s: python-binding
    • Labels:
      None
    • Environment:
      Operating System: Windows
      Python: 3.6.4
      qpid-proton: 0.24.0

      Description

      I'm using following python code to send messages to the devices (/messages/devicebound) which are connected to the azure iot hub:

      import json
      from base64 import b64encode, b64decode
      from hashlib import sha256
      from hmac import HMAC
      from time import time
      from urllib.parse import quote_plus, urlencode
      
      from proton import ProtonException, Message
      from proton.utils import BlockingConnection
      
      
      class IotHub:
          def __init__(self):
              self._hostname = f"example-hub.azure-devices.net"
              self._username = f"iothubowner@sas.root.example-hub.azure-devices.net"
      
              self._blocking_connection = None
              self._sender = None
      
              self.connect()
      
          @staticmethod
          def generate_sas_token(uri: str, policy: str, key: str, expiry: float = None):
              if not expiry:
                  expiry = time() + 3600  # Default to 1 hour.
              encoded_uri = quote_plus(uri)
              ttl = int(expiry)
              sign_key = f"{encoded_uri}\n{ttl}"
              signature = b64encode(HMAC(b64decode(key), sign_key.encode(), sha256).digest())
              result = {"sr": uri, "sig": signature, "se": str(ttl)}
              if policy:
                  result["skn"] = policy
      
              return f"SharedAccessSignature {urlencode(result)}"
      
          def connect(self):
              # create credentials
              password = self.generate_sas_token(self._hostname,
                                                 "iothubowner", "key",
                                                 time() + 31557600)  # ttl = 1 Year
      
              # establish connection
              self._blocking_connection = BlockingConnection(f"amqps://{self._hostname}", allowed_mechs="PLAIN",
                                                             user=self._username, password=password,
                                                             heartbeat=30)
              self._sender = self._blocking_connection.create_sender("/messages/devicebound")
      
          def send(self, message: dict, serial_number: str):
              message = Message(address="/devices/{serial_number}/messages/devicebound".format(serial_number=serial_number),
                                body=bytes(json.dumps(message, separators=(",", ":")), "utf-8"))
              message.inferred = True  # disable message encoding
              self._sender.send(message, timeout=20)
      

      The problem is now that when I don't send any message for some seconds I get following exepction while sending a message:

      Connection amqps://example-hub.azure-devices.net:amqps disconnected: Condition('amqp:resource-limit-exceeded', 'local-idle-timeout expired')
      

      Whats the reason for that? How can I solve that?

      Thank you for help.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              andreas.fendt Andreas Fendt
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: