-
-
Notifications
You must be signed in to change notification settings - Fork 1k
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
serialport memory leak on raspberry pi 3 #1477
Comments
update, on the latest version, it didn't crash, but still using big amount of memory (700+ MB) for some reason, compared to windows counterpart that only use 25MB of memory |
nodejs 6.x installed, everything seems fine |
So a memory leak on node 6 but not on node 8?
…On Tue, Feb 13, 2018, 8:54 AM fdedraco ***@***.***> wrote:
nodejs 6.x installed, everything seems fine
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1477 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABlbjUciIvvxrb6N4WMOkUImm3Nb-78ks5tUZQVgaJpZM4SDqkZ>
.
|
umm the other way, it leaks on v8 and v9, running fine on v6 |
gcc might make it fail, I'm not sure it would cause a memory leak |
Hi... I have the same problem on Raspberry Pi 3 with:
both with "data" and "readable" event listeners; it uses 700MB of memory at least. Thanks in advance! Nicola |
Hello, the same on :
tested with :
I'm using SerialPort as dependency of modbus-serial, in program running on RPi2, which collecting data from few PLCs. Memory consumption initially is about 50MB, growing to 220MB after 24h, and to 310MB after next 12h. RPi is not fast, so when mem utilization is high, GC runs take some time - it causing many timeouts when reading modbus. Additionally, I found closed #1187 issue, and example code provided in them (after remove port.write - only open and close port cycle) quickly causing memory leak on my Ubuntu PC.
When this code is running, forcing GC from DevTools inspector drops memory usage only by few MBs. EDIT :
EDIT 2 :
so definitely problem is in port.open, port.close or both of them. |
I found the main cause of memory "leak" (there is no leak in strict sense, that's why valgrind doesn't find it) - native Poller object is created each time we create SerialPort - but never get disposed. If I understand correctly, it should happen when on JS side null is assigned to Poller object, then GC run and call WeakCallback (attached during wrap Poller object), but v8 doc state : "There is no guarantee as to when or even if the callback is invoked". Quick & dirty solution I use in my production program is to add
and remove assertion in node_modules/nan/nan_object_wrap.h
that's do the trick, and memory consumption does not rise. For sure it isn't valid or elegant way to do this - I have virtually no experience in C++, so my question is how and where manually and properly dispose Poller object ? |
We can't modify Nan but I'm sure there is another way! I'm on leave this month (taking time off from coding in general) but I'm very happy to see this investigation start to bear fruit! |
I think I have real solution without have to modify Nan. The key was to call I have added new method "destroy" to Poller, which is intended to be called from JS after |
Can you open a pull request?
…On Wed, May 30, 2018, 6:18 PM shodan8192 ***@***.***> wrote:
I think I have real solution without have to modify Nan. The key was to
call obj->persistent().Reset(); before delete obj;
I have added new method "destroy" to Poller, which is intended to be
called from JS after poller.stop() and before assigning null to poller
object. For all necessary changes, I made a patch
poller.patch.gz
<https://github.com/node-serialport/node-serialport/files/2055818/poller.patch.gz>
against commit d829ada
<d829ada>,
for You and anyone who is interested, to be reviewed and maybe to merge if
it's ok.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1477 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABlblac32h6F-9I7PPiAUjyd-8pIVGXks5t3xrMgaJpZM4SDqkZ>
.
|
Pull request been has opened. I can also mention, that my telemetry program, after patch of serialport have two weeks of uptime now, and memory usage is stable. |
I merged #1572 (your fix) and I'll open another issue about finding a way to handle the case where destroy doesn't get called because the object went out of scope. I'll keep this issue open until the patch has been released. |
SerialPort Version: 6.0.4 & 6.1.4
NodeJS Version: 8.9.x & 9.5.0
Operating System and Hardware Platform:
raspbian strectch lite
onraspberry pi 3
Have you checked the right version of the api docs?: yes, it kinda works as intended
Are you having trouble installing and you checked the Installation Special Cases docs? just normal autocompile
Are you using Electron and have you checked the Electron Docs?: no
Summary of Problem
i was very happy that my project is almost complete but when i test the project on raspberry pi it crashes after running for a while, it crashes, i suspect it's some kind of memory leak, since the node memory usage is increased overtime, console error at bottom of the post
Steps and Code to Reproduce the Issue
i make a server that can change used serial port when needed
re-config script:
event handlers:
didn't crash when the said function didn't called
edit: no data is received yet from serial
console error:
The text was updated successfully, but these errors were encountered: