This repository was archived by the owner on Sep 16, 2024. It is now read-only.
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Pycom frozen MQTTClient leaks memory when publishing messages under 1.11.0.b1 #108
Open
Description
I'm seeing this on a WiPy 2.0 running my own build of 1.11.0.b1. The only changes I made to the firmware was to add datetime into the frozen modules area. In the test case below I didn't even load datetime so I believe that's irrelevant. This same memory leak seems to occur in the last release of the firmware as well when the frozen MQTTClient was introduced (at least that's how it looked to me).
(sysname='WiPy', nodename='WiPy', release='1.11.0.b1', version='063e199 on 2017-12-19', machine='WiPy with ESP32')
-
Exact steps to cause this issue
- Modify the boot.py and main.py test case below with your own MQTT broker URL, user, pass, WiFi creds, etc.
- Transfer the main.py and boot.py onto a WiPy 2.0 running 1.11.0.b1
- Reset the WiPi and let it loop sending messages until it runs out of RAM
-
Here's the main.py
import MQTTConst
import micropython
import gc
from MQTTClient import MQTTClient
from machine import Timer
class HeartbeatTimer:
def __init__(self):
self._mqtt_client = MQTTClient("tester", True, MQTTConst.MQTTv3_1_1)
self._mqtt_host = '192.168.1.66'
self._mqtt_port = 1883
self._mqtt_topic = 'realtime'
self._mqtt_user = 'myusername'
self._mqtt_pass = 'secr3t'
self._mqtt_qos = 0
self._iters = 0
self._mqtt_client.configEndpoint(self._mqtt_host, self._mqtt_port)
self._mqtt_client._user = self._mqtt_user
self._mqtt_client._password = self._mqtt_pass
self._mqtt_client.connect()
self._alarm = Timer.Alarm(self._wakeup_handler, arg=self, s=0.25, periodic=True)
def _wakeup_handler(self, arg):
self._iters += 1
print("iteration", self._iters)
self._mqtt_client.publish("events", "hello!!", 0, False)
micropython.mem_info()
gc.collect()
print("Starting up...")
# software versions
print("Version Information: ", os.uname())
# create our timer
hbtimer = HeartbeatTimer()
# startup is complete so let's take a nap and wait for something to wake us
machine.sleep()
And here's the boot.py
# boot.py -- run on boot-up
import os
import machine
from machine import UART
from network import WLAN
# ???
uart = UART(0, 115200)
os.dupterm(uart)
# setup WLAN and assign static ip
# originallu taken from: http://docs.micropython.org/en/latest/wipy/wipy/tutorial/wlan.html
wlan = WLAN()
if machine.reset_cause() != machine.SOFT_RESET:
wlan.init(mode=WLAN.STA)
# configuration below MUST match your home router settings!!
wlan.ifconfig(config=('192.168.1.123', '255.255.255.0', '192.168.1.1', '8.8.8.8'))
if not wlan.isconnected():
# change the line below to match your network ssid, security and password
wlan.connect('WiFiSSID', auth=(WLAN.WPA2, 'V3RySECRET!'), timeout=5000)
while not wlan.isconnected():
machine.idle() # save power while waiting
- And here's the beginning and end of a test run showing the problem
rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff9028,len:8
load:0x3fff9030,len:1060
load:0x4009fa00,len:0
ho 12 tail 0 room 4
load:0x4009fa00,len:15160
entry 0x400a0644
Starting up...
Version Information: (sysname='WiPy', nodename='WiPy', release='1.11.0.b1', version='063e199 on 2017-12-19', machine='WiPy with ESP32')
Packet sent. (Length: 44)
MicroPython 063e199 on 2017-12-19; WiPy with ESP32
Type "help()" for more information.
>>> iteration 1
stack: 816 out of 5120
GC: total: 67008, used: 26448, free: 40560
No. of 1-blocks: 201, 2-blocks: 21, max blk sz: 512, max free sz: 2529
iteration 2
stack: 816 out of 5120
GC: total: 67008, used: 24992, free: 42016
No. of 1-blocks: 145, 2-blocks: 17, max blk sz: 512, max free sz: 2529
iteration 3
stack: 816 out of 5120
GC: total: 67008, used: 25040, free: 41968
No. of 1-blocks: 146, 2-blocks: 18, max blk sz: 512, max free sz: 2529
iteration 4
stack: 816 out of 5120
GC: total: 67008, used: 25088, free: 41920
No. of 1-blocks: 147, 2-blocks: 19, max blk sz: 512, max free sz: 2529
iteration 5
stack: 816 out of 5120
GC: total: 67008, used: 25152, free: 41856
No. of 1-blocks: 147, 2-blocks: 21, max blk sz: 512, max free sz: 2529
iteration 6
stack: 816 out of 5120
GC: total: 67008, used: 25200, free: 41808
No. of 1-blocks: 148, 2-blocks: 22, max blk sz: 512, max free sz: 2529
iteration 7
...................................................
GC: total: 67008, used: 66272, free: 736
No. of 1-blocks: 908, 2-blocks: 801, max blk sz: 512, max free sz: 38
iteration 831
stack: 816 out of 5120
GC: total: 67008, used: 66256, free: 752
No. of 1-blocks: 905, 2-blocks: 802, max blk sz: 512, max free sz: 38
iteration 832
stack: 816 out of 5120
GC: total: 67008, used: 66288, free: 720
No. of 1-blocks: 905, 2-blocks: 803, max blk sz: 512, max free sz: 38
iteration 833
stack: 816 out of 5120
GC: total: 67008, used: 66336, free: 672
No. of 1-blocks: 906, 2-blocks: 804, max blk sz: 512, max free sz: 36
iteration 834
stack: 816 out of 5120
GC: total: 67008, used: 66384, free: 624
No. of 1-blocks: 907, 2-blocks: 805, max blk sz: 512, max free sz: 33
iteration 835
stack: 816 out of 5120
GC: total: 67008, used: 66432, free: 576
No. of 1-blocks: 908, 2-blocks: 806, max blk sz: 512, max free sz: 30
iteration 836
stack: 816 out of 5120
GC: total: 67008, used: 66480, free: 528
No. of 1-blocks: 909, 2-blocks: 807, max blk sz: 512, max free sz: 27
iteration 837
stack: 816 out of 5120
GC: total: 67008, used: 66528, free: 480
No. of 1-blocks: 910, 2-blocks: 808, max blk sz: 512, max free sz: 24
Packet sent. (Length: 17)
iteration 838
stack: 816 out of 5120
GC: total: 67008, used: 66736, free: 272
No. of 1-blocks: 912, 2-blocks: 810, max blk sz: 512, max free sz: 11
iteration 839
stack: 816 out of 5120
GC: total: 67008, used: 66752, free: 256
No. of 1-blocks: 913, 2-blocks: 810, max blk sz: 512, max free sz: 9
iteration 840
stack: 816 out of 5120
GC: total: 67008, used: 66784, free: 224
No. of 1-blocks: 915, 2-blocks: 810, max blk sz: 512, max free sz: 7
iteration 841
stack: 816 out of 5120
GC: total: 67008, used: 66832, free: 176
No. of 1-blocks: 916, 2-blocks: 811, max blk sz: 512, max free sz: 6
iteration 842
stack: 816 out of 5120
GC: total: 67008, used: 66880, free: 128
No. of 1-blocks: 917, 2-blocks: 812, max blk sz: 512, max free sz: 6
iteration 843
stack: 816 out of 5120
GC: total: 67008, used: 66816, free: 192
No. of 1-blocks: 911, 2-blocks: 813, max blk sz: 512, max free sz: 6
iteration 844
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 845
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 846
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 847
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 848
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 849
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 850
stack: 816 out of 5120
GC: total: 67008, used: 66800, free: 208
No. of 1-blocks: 913, 2-blocks: 815, max blk sz: 512, max free sz: 6
iteration 851
stack: 816 out of 5120
GC: total: 67008, used: 66896, free: 112
No. of 1-blocks: 917, 2-blocks: 816, max blk sz: 512, max free sz: 6
iteration 852
stack: 816 out of 5120
GC: total: 67008, used: 66832, free: 176
No. of 1-blocks: 911, 2-blocks: 817, max blk sz: 512, max free sz: 6
iteration 853
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 854
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 855
stack: 816 out of 5120
GC: total: 67008, used: 66912, free: 96
No. of 1-blocks: 914, 2-blocks: 818, max blk sz: 512, max free sz: 6
iteration 856
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
iteration 857
Unhandled exception in callback handler
Traceback (most recent call last):
File "main.py", line 32, in _wakeup_handler
File "MQTTClient.py", line 161, in publish
MemoryError:
Unhandled exception in thread started by <bound_method>
Traceback (most recent call last):
File "MQTTMsgHandler.py", line 257, in _io_thread_func
File "MQTTMsgHandler.py", line 232, in _verify_connection_state
File "MQTTMsgHandler.py", line 210, in _send_pingreq
File "MQTTMsgHandler.py", line 150, in priority_send
File "MQTTMsgHandler.py", line 223, in _send_packet
File "MQTTMsgHandler.py", line 220, in _send_packet
MemoryError:
iteration 858