Coder Social home page Coder Social logo

Comments (14)

mscdex avatar mscdex commented on May 29, 2024

What else would you expect? You're creating new channel streams every second, regardless of whether or not the callback has been executed and the 'exit' event has been emitted on the stream?

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Unfortunately, destruction of streams doesn't prevent memory leak. For example: https://dl.dropboxusercontent.com/u/3261328/testssh2.js

What should I do in order to execute a command every second using a single ssh connection?

from ssh2.

mscdex avatar mscdex commented on May 29, 2024

I would suggest wrapping your exec() call into a separate function. Call it immediately on 'ready' and then on the stream's 'exit' event, do a setTimeout(doExec, 1000);.

I would also suggest using some profiling tools to verify that there is in fact a leak and if so, where it is actually located.

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Thank you! I'll try to do as you suggest.

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Unfortunately, it didn't help.
I tried to run this code: https://dl.dropboxusercontent.com/u/3261328/testssh2_setTimeout.js
Here the results: https://dl.dropboxusercontent.com/u/3261328/testssh2_results.txt

Something like ssh.exec('watch -n1 cmd', function(err, stream) {...} ) runned once don't cause leakage.

from ssh2.

mscdex avatar mscdex commented on May 29, 2024

setTimeout(doExec(), 1000); should be setTimeout(doExec, 1000);

EDIT: Additionally, you cannot expect it to execute exactly every second due to server latency and especially the routinely forced garbage collection.

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Oh, it's my mistake...
But the memory leak is still present: https://dl.dropboxusercontent.com/u/3261328/testssh2_results2.txt

you cannot expect it to execute exactly every second

It's not a big problem. In my task such precision is not important. And manual GC will be turned off in production.

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Any ideas?

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

What do you think, it's a bug or my mistake?
I see the only solution at the moment: use the watch -n 1

from ssh2.

stinger1206 avatar stinger1206 commented on May 29, 2024

I have the same problem.

from ssh2.

mscdex avatar mscdex commented on May 29, 2024

After much digging (special thanks to heapdump) and investigation, I found the leak. It should now be plugged in the master branch.

Can both of you give it a try?

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Oh, thank u! It's much better now.
Unfortunately, leak is still there, but not so fast as before.
There is my tests: https://dl.dropboxusercontent.com/u/3261328/testssh2_results3.txt

from ssh2.

mscdex avatar mscdex commented on May 29, 2024

@VadimIpatov Let it run for much longer. I have been running it for several hours now (with manual full GCs to more easily ensure no leaks are present). During this time, it has been hovering around 3.17mb for the heap (process.memoryUsage().heapUsed) and 20mb for the rss (process.memoryUsage().rss).

from ssh2.

VadimIpatov avatar VadimIpatov commented on May 29, 2024

Yeah, you're right. It works! :)
Thank you!

no_leak

from ssh2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.