Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak #1

Open
andwaal opened this issue Sep 14, 2019 · 1 comment
Open

Possible memory leak #1

andwaal opened this issue Sep 14, 2019 · 1 comment
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@andwaal
Copy link

andwaal commented Sep 14, 2019

Hi
First of all thanks for a good program!

After a couple of days running this on my Rpi3 it stopped sending data to HA and I was not able to SSH into the instance. The PI is a fresh install only running this service.

In syslog I found these:

Sep 13 22:47:45 raspberrypi ams_han_decoder.pl[245]: Decoding HDLC frame failed: Can't pipe to  mosquitto_pub -h 192.168.10.69 -s -t sensor/ams: Cannot allocate memory at /home/pi/ams-han-decoder/ams_han_decoder.pl line 115.
Sep 13 22:47:45 raspberrypi ams_han_decoder.pl[245]: #011main::send_json("{\x{a}   \"data\" : {\x{a}      \"power_active_import\" : {\x{a}         \"des"...) called at /home/pi/ams-han-decoder/ams_han_decoder.pl line 434
Sep 13 22:47:45 raspberrypi ams_han_decoder.pl[245]: #011main::decode_hdlc_frame("\x{a0}*A\x{8}\x{83}\x{13}\x{4}\x{13}\x{e6}\x{e7}\x{0}\x{f}\@\x{0}\x{0}\x{0}\x{0}\x{1}\x{1}\x{2}\x{3}\x{9}\x{6}\x{1}\x{0}\x{1}\x{7}\x{0}\x{ff}\x{6}\x{0}\x{0}\x{5}\x{da}\x{2}\x{2}\x{f}\x{0}\x{16}\x{1b}J\x{ad}", 42, 0, 10) called at /home/pi/ams-han-decoder/ams_han_decoder.pl line 189
Sep 13 22:47:45 raspberrypi ams_han_decoder.pl[245]: #011eval {...} called at /home/pi/ams-han-decoder/ams_han_decoder.pl line 189
Sep 13 22:47:45 raspberrypi ams_han_decoder.pl[245]: #011main::parse_stream(GLOB(0x1f61648)) called at /home/pi/ams-han-decoder/ams_han_decoder.pl line 83
Sep 13 22:47:47 raspberrypi ams_han_decoder.pl[245]: Decoding HDLC frame failed: Can't pipe to  mosquitto_pub -h 192.168.10.69 -s -t sensor/ams: Cannot allocate memory at /home/pi/ams-han-decoder/ams_han_decoder.pl line 115.
Sep 13 22:47:47 raspberrypi ams_han_decoder.pl[245]: #011main::send_json("{\x{a}   \"data\" : {\x{a}      \"power_active_import\" : {\x{a}         \"des"...) called at /home/pi/ams-han-decoder/ams_han_decoder.pl line 434

The program is running as a service in systemd:

[Unit]
Description=AMS HAN decoder

[Service]
Environment=HOME=/home/pi
ExecStart= /home/pi/ams-han-decoder/ams_han_decoder.pl -m AIDON_V0001 -p ' mosquitto_pub -h 192.168.10.69 -s -t sensor/ams' /dev/ttyUSB0

[Install]
WantedBy=multi-user.target

After rebooting I then watched the processes in htop and could see the memory use of the service stedely raising, which leads me to the conclution that that a memory leak is the reason behind my crash.

I was able to solve this by adding auto restart of the service in systemd, but this should not be needed.

So the "working" systemd service now looks like this

[Unit]
Description=AMS HAN decoder

[Service]
Environment=HOME=/home/pi
ExecStart= /home/pi/ams-han-decoder/ams_han_decoder.pl -m AIDON_V0001 -p ' mosquitto_pub -h 192.168.10.69 -s -t sensor/ams' /dev/ttyUSB0
Restart=always
RuntimeMaxSec=3600

[Install]
WantedBy=multi-user.target
@robinsmidsrod robinsmidsrod added bug Something isn't working help wanted Extra attention is needed labels Aug 25, 2020
@robinsmidsrod robinsmidsrod self-assigned this Aug 25, 2020
@robinsmidsrod
Copy link
Owner

@andwaal I've confirmed the issue as well, but I used the method mentioned in the README (systemd memory limit) to keep it under control.

The -k parameter helps mitigate the issue somewhat, as the issue occurs when the program mentioned by the -p parameter is executed/forked. If you don't use the -p parameter at all, then I think the issue shouldn't happen.

If you don't use -p then you'll have to find another way to pipe STDOUT (the JSON data) where you want it. If you come up with a better systemd unit file for doing that, then I'm very interested.

Finally, if you're able to figure out where the memory leak is actually coming from I would very much like to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants