openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

MaxListenersExceededWarning: Possible EventEmitter memory leak detected and Regular Expression Denial of Service

Open marck283 opened this issue 2 years ago • 3 comments

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

  1. Initialize a new Node.js project;
  2. 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

marck283 avatar Oct 04 '23 14:10 marck283

Thanks for the report, we're looking into upgrading.

rattrayalex avatar Oct 05 '23 18:10 rattrayalex

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.

rattrayalex avatar Oct 05 '23 19:10 rattrayalex

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 })

rattrayalex avatar Oct 05 '23 20:10 rattrayalex

We don't expect to action this directly, so closing. We are planning to remove our node-fetch dependency before long.

rattrayalex avatar Jul 08 '24 19:07 rattrayalex