question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible memory leak in nsqjs writer

See original GitHub issue

Hi,

I’m using NodeJS 11.5.0 did a simple benchmark of the nsqjs Writer (v0.12.0) and found a possible memory leak, possibly the same kind as in https://github.com/dudleycarr/nsqjs/issues/211 which was related to the nsqjs Reader. You’ll find attached the app.js script I used for testing as well as the package.json and test.json file. Basically, it uses nsqjs Writer as a middleware for Koa (code was mostly taken from https://github.com/dudleycarr/nsqjs/issues/202#issuecomment-346075638). For the benchmark, I simply used a while true loop with curl, sending a small json content as POST data to the Koa endpoint (example: while true; do curl -XPOST -d @test.json http://127.0.0.1:3000/test -H 'Accept: application/json' -H 'Content-Type: application/json'; done).

Below is the result of the heap profiling. Heap snapshots were taken every 10 minutes. As you can see, the heap grows quite rapidly (from ~20 to ~140 MB). Apparently, this seems related to the debug module.

heapdump_leak

To confirm this, I did something really dirty but effective. I commented out every mention to the debug module in nsqdconnection.js and writer.js and went through the same process. Heap profiling result is below. In this case, the heap is stable.

heapdump_ok

I’m far from being a NodeJS guru though 😉. So if I’m missing something important or if my testing code is buggy, don’t hesitate to tell me. Still, it really looks like the same behavior as in https://github.com/dudleycarr/nsqjs/issues/211

app.zip

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ilikegolfcommented, Dec 1, 2022

After further investigation, I do not believe my memory leak was caused thensqjs:Writer class. However, thank you so much for your responsiveness @dudleycarr.

1reaction
dudleycarrcommented, Nov 28, 2022

@ilikegolf I’ll take a look this week to see if I can reproduce the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nsqjs - npm
Allows messages to be sent to an nsqd. Available Writer options: tls: false. Use TLS if nsqd has TLS support enabled. tlsVerification: true...
Read more >
nsqjs - Bountysource
Hi,. I'm using NodeJS 11.5.0 did a simple benchmark of the nsqjs Writer (v0.12.0) and found a possible memory leak, possibly the same...
Read more >
Node.js Memory Leak Detection: How to Debug & Avoid Them
Learn what Node.js memory leaks are. Discover common causes and go through the whole debugging process, from detection to fixing and ...
Read more >
Eradicating Memory Leaks In Javascript - LambdaTest
Though the garbage collection method is highly effective, it is still possible for Javascript memory leaks to occur.
Read more >
The 4 Types of Memory Leaks in Node.js and How to Avoid ...
It is very common for software to introduce bugs. How we manage them is the real issue. One of the most common bugs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found