ruuvitag-sensor leaving processes behind and causing out of memory crashes
sevesalm opened this issue · 1 comments
I use the reactive way to read the data. This allows me to specify a timeout but return immediately when new data is received. The code below works fine, except my Raspberry crashes in an hour when the memory gets full of leftover processes. The memory leak is caused purely by the first line in the snipped below, ie. getting the rx subject.
ruuvi_subject = RuuviTagReactive(['AA:AA:AA:AA:AA:AA]).get_subject()
# The line above alone is enough to cause the issue. Anything below is not relevant.
sensor_data = ruuvi_subject\
.map(lambda x: {x[0]: x[1]})\
.merge(rx.Observable.timer(3000).map(lambda x: {}))\
.to_blocking()\
.first()
ruuvi_subject.dispose()
After each invocation, I see new set of these appearing in addition to all previous ones. Additionally I see new entries of the python script which is running the code. Exiting the script seems to be the only way to cleanup.
$ ps aux
...
root 4892 0.0 0.3 7640 2996 pts/4 Ss+ 18:15 0:00 /usr/bin/sudo -n hcitool -i hci0 lescan2 --duplicates
root 4893 0.0 0.3 7640 3040 pts/5 Ss+ 18:15 0:00 /usr/bin/sudo -n hcidump -i hci0 --raw
root 4894 0.1 0.0 2424 584 pts/4 S+ 18:15 0:00 hcitool -i hci0 lescan2 --duplicates
root 4895 1.1 0.0 2368 480 pts/5 S+ 18:15 0:00 hcidump -i hci0 --raw
There is a closed similar issue here:
Am I doing something wrong or is there an issue regarding cleanup in ruuvitag-sensor?
The similar thing happens with Bleson adapter. Ie. I see 5 new entries appearing of my script (no hcitool or hcidump this time) on each invocation. So this is not about hcitool/hcidump but something else.
Environment (please complete the following information):
- OS: Raspbian GNU/Linux 10 (buster)
- ruuvitag_sensor package version: 1.1.0
- RuuviTag firmware version: 2.5.9
- Data format: 5
Filing issues is always helpful: I solved this 😅
I noticed that I did not cleanup properly afterall. I missed calling the stop()
method for the RuuviTagReactive
object. It was not enough to dispose just the subject as I thought. Seems to work properly now. Below is the working snipped.
ruuvi_reactive = RuuviTagReactive(['AA:AA:AA:AA:AA:AA'])
sensor_data = ruuvi_reactive\
.get_subject()\
.map(lambda x: {x[0]: x[1]})\
.merge(rx.Observable.timer(config.getint('SENSOR_POLL_TIMEOUT')).map(lambda x: {}))\
.to_blocking()\
.first()
ruuvi_reactive.stop() # <--- This is the cleanup