Closed jmutanen closed 7 years ago
I have exactly the same problem running the package on a raspberry pi.
I am also having this problem after the nodejs server runs for a few minutes.
I quickly looked to the code and it seems that two file descriptions (ctx_mt->mtp_r and ctx_mt->mtp_w) opened in modbus-rtu.c:1097 are never closed.
int mtp[2]; if (pipe(mtp) == -1) { fprintf(stderr, "ERROR Can't create pipe (%s)\n", strerror(errno)); modbus_free(ctx); return NULL; } ctx_mt->mtp_r = mtp[0]; ctx_mt->mtp_w = mtp[1];
I made a fix for this one, pull request created. Fix available in https://github.com/jmutanen/nodejs_libmodbus.
There was still one issue. I hade to make one small modification.
nodejs_libmodbus/modbus.js::createMasterRtu and api.Destroy function:
mb.close(ctx); => mb.close_mt(ctx);
Should the same modifications be applied in createMasterTcp api.Destroy function?
jmutanen,
I did the following:
I still receive the following errors after it runs for few minutes: ERROR Can't create pipe (Too many open files) ERROR createMasterRtu: Too many open files
Did I do something wrong in applying the patches or is there still an issue?
Thank you for your help!
Hi,
Did you build the package with node-gyp?
./make_libmodbus.sh && node-gyp configure && node-gyp build
Cheers, -Jussi
That was the problem. I did not rebuild with node-gyp. Seems to be working fine now. Thanks!
When I run modbus example (Creating master device) multiple times in a row on my Raspberry Pi I got finally an error while creating new master context:
ERROR Can't create pipe (Too many open files)
I use createConRtu for con. It looks like some resources are not freed in the close or free functions?
https://www.npmjs.com/package/modbus#creating-master-device-client