Hey team,
We’ve been experiencing memory leak issues in our production environment when using LangChain.
## How We Found It
We noticed memory was continuously growing and not being released, especially during operations that involved retries. After monitoring, we saw a clear pattern:
The memory would spike during tool executions with retries and **never get released**, even after the operations completed.
## Investigation
After digging into the issue, we tracked it down to the dependencies. Running `npm ls p-retry` revealed that multiple LangChain packages are using an outdated version:
@langchain/community@1.0.2 → p-retry@4.6.2
@langchain/core@1.0.4 → p-retry@4.6.2
@langchain/langgraph@1.0.2 → p-retry@4.6.2
## Root Cause
`p-retry@4.6.2` (from July 2021) has a known memory leak issue where event listeners accumulate over time and are never cleaned up. With each retry attempt, more listeners are added but never removed, causing memory to continuously grow.
## The Fix
Upgrading to `p-retry@7.x` fixes this with:
- Proper event listener cleanup (uses `{once: true}` and explicit removal)
- AbortSignal support for cancellation (v4 had none)
- Time-based retry limits via `maxRetryTime`
- Better network error detection
## Breaking Changes
- Needs Node.js 18+ (from 10+)
- ESM instead of CommonJS
- `forever` option removed (use `retries: Infinity` instead)
The core API is mostly compatible, so migration should be straightforward.
## Links
- [Full comparison v4.6.2 → v7.1.0]( Comparing v4.6.2...v7.1.0 · sindresorhus/p-retry · GitHub )
- [Release notes]( Release v7.0.0 · sindresorhus/p-retry · GitHub )
Has anyone else experienced similar memory issues? Would love to hear if this upgrade is already planned or if there are concerns about the breaking changes.
Thanks!
