This is related to #101 and #81 (I think) but I have a single simple script (attached, zipped for github reasons) that reproduces both problems by adjusting the size of the message. Publishing one particular message gives MemoryError: memory allocation failed, while larger messages than that stop the client from interacting with the broker, resulting in disconnects.
Platform: UnexpectedMaker FeatherS2; No Peripherals
USB: power and serial; LiPo connected
boot_out.txt : Adafruit CircuitPython 7.2.5 on 2022-04-06; FeatherS2 with ESP32S2
Board ID:unexpectedmaker_feathers2
[Just tested on Adafruit MagTag and the behavior is the same as the FeatherS2.]
Working control platform: Same data (up to FRAME size 768) works with same broker CP and lib versions
and client running on Feather M4 Express with AirLift Wing
MQTT Broker: mosquitto version 1.4.15
By varying the size of the message (json encoded) you get different results:
payload = {'FRAME': [25.8683] * SIZE, 'C': 24.3511, 'RH': 16.9207}
SIZE <=313
NO ERROR, payload is published and read back on subscribed topic.
SIZE = 314
Payload is published, but MemoryError is thrown when mqtt_client.loop() is called
Traceback (most recent call last):
File "main.py", line 70, in
File "adafruit_minimqtt/adafruit_minimqtt.py", line 805, in loop
File "adafruit_minimqtt/adafruit_minimqtt.py", line 854, in _wait_for_msg
File "adafruit_minimqtt/adafruit_minimqtt.py", line 902, in _sock_exact_recv
MemoryError: memory allocation failed, allocating 4294952961 bytes
SIZE >=315
Broker never receives PUBLISH from client;
client stops sending PINGREQ; Broker disconnects @ timeout.
Client traceback:
Traceback (most recent call last):
File "main.py", line 63, in
File "adafruit_minimqtt/adafruit_minimqtt.py", line 802, in loop
File "adafruit_minimqtt/adafruit_minimqtt.py", line 565, in ping
MMQTTException: PINGRESP not returned from broker.
SIZE >=315 [alternate while loop timing]
If one adjusts the while loop to force a second publish before the timeout,
the 2nd time is publish is called, a message of the correct size
gets to broker; broker sends message back, reports socket error and disconnects.
Client traceback:
Traceback (most recent call last):
File "main.py", line 70, in
File "adafruit_minimqtt/adafruit_minimqtt.py", line 802, in loop
File "adafruit_minimqtt/adafruit_minimqtt.py", line 556, in ping
OSError: [Errno 104] ECONNRESET
Broker Log (2nd publish):
1649712800: Received PUBLISH from coop_v0 (d0, q0, r0, m0, 'test_zz', ... (2875 bytes))
1649712800: Sending PUBLISH to coop_v0 (d0, q0, r0, m0, 'test_zz', ... (2875 bytes))
1649712800: Socket error on client coop_v0, disconnecting.
main.zip