openai-node
openai-node copied to clipboard
MaxListenersExceededWarning: Possible EventEmitter memory leak detected and Regular Expression Denial of Service
Confirm this is a Node library issue and not an underlying OpenAI API issue
- [X] This is an issue with the Node library
Describe the bug
Using Node.js version 20.x or later in a project that depends on node-fetch prior to version 3.2.5 results in Node prompting a MaxListenersExceededWarning: Possible EventEmitter memory leak detected warning (as can be seen here). However, node-fetch versions between 3.1.0 and 3.2.10 also suffer from a Regular Expression Denial of Service (as can be seen here). Installing [email protected] seems to solve both problems.
To Reproduce
- Initialize a new Node.js project;
- install node-fetch prior to version 3.2.10 or packages that depend on node-fetch prior to version 3.2.10.
Code snippets
No response
OS
Windows 11
Node version
Node v20.7.0
Library version
openai v4.11.1
Thanks for the report, we're looking into upgrading.
We can't upgrade to node-fetch 3.x because it's ESM-only, and this library supports CJS as well.
We're looking into backporting the fix for that issue to the 2.x line.
FWIW, I don't believe the memory leak effects should be very significant, so this warning should be safe to ignore.
In the meantime, @marck283 you can work around this by installing [email protected] and pass it in to the library:
import nodeFetch from 'node-fetch'
import OpenAI from 'openai'
const client = new OpenAI({ fetch: nodeFetch })
We don't expect to action this directly, so closing. We are planning to remove our node-fetch dependency before long.