Repository: adafruit/Adafruit_CircuitPython_MiniMQTT (language: python)

Issue:
can not make mqtt_client.loop() shorter as 1 sec
i try:
```
ts=time.monotonic()
#mqtt_client.loop() # every second check if remote command comes in
mqtt_client.loop(timeout=0.01)
print(f"___ mqtt_client loop {(time.monotonic()-ts)} sec")
```

more see:
[test GIT of mqtt pub sub REMOTE BLINKY](https://github.com/MyRaspberry/PICO_W_MQTT_pub_sub)


Discussion / hints:
Do you explicitly set `socket_timeout` and `recv_timeout` when initializing the `MQTT` object ?

Fix patch:
diff --git a/adafruit_minimqtt/adafruit_minimqtt.py b/adafruit_minimqtt/adafruit_minimqtt.py
index 7ffb723..2ec0100 100644
--- a/adafruit_minimqtt/adafruit_minimqtt.py
+++ b/adafruit_minimqtt/adafruit_minimqtt.py
@@ -1029,6 +1029,13 @@ def loop(self, timeout: float = 0) -> Optional[list[int]]:
         :param float timeout: return after this timeout, in seconds.
 
         """
+        if timeout < self._socket_timeout:
+            raise MMQTTException(
+                # pylint: disable=consider-using-f-string
+                "loop timeout ({}) must be bigger ".format(timeout)
+                + "than socket timeout ({}))".format(self._socket_timeout)
+            )
+
         self._connected()
         self.logger.debug(f"waiting for messages for {timeout} seconds")
         if self._timestamp == 0:


Test patch:
diff --git a/tests/test_loop.py b/tests/test_loop.py
index 6a762fd..0115a5d 100644
--- a/tests/test_loop.py
+++ b/tests/test_loop.py
@@ -68,6 +68,26 @@ def test_loop_basic(self) -> None:
                 assert ret_code == expected_rc
                 expected_rc += 1
 
+    # pylint: disable=invalid-name
+    def test_loop_timeout_vs_socket_timeout(self):
+        """
+        loop() should throw MMQTTException if the timeout argument
+        is bigger than the socket timeout.
+        """
+        mqtt_client = MQTT.MQTT(
+            broker="127.0.0.1",
+            port=1883,
+            socket_pool=socket,
+            ssl_context=ssl.create_default_context(),
+            socket_timeout=1,
+        )
+
+        mqtt_client.is_connected = lambda: True
+        with self.assertRaises(MQTT.MMQTTException) as context:
+            mqtt_client.loop(timeout=0.5)
+
+        assert "loop timeout" in str(context.exception)
+
     def test_loop_is_connected(self):
         """
         loop() should throw MMQTTException if not connected