Skip to content

Possible EventEmitter memory leak detected #197

@leobel

Description

@leobel

Hello, I've an http server using the same InteractionContext to handle multiple request creating instances of TxSubmissionClient (without closing any of this clients after response), after several requests I end up with this warning:

(node: 8) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 
11 message listeners added to [WebSocket]. Use emitter.setMaxListeners() to increase limit

@KtorZ already mention the use of submitTx method (without creating any client) and sharing the InteractionContext between requests, but taking a look to the source code of TxSubmissionClient it looks like a wrapper of the underlying websocket with a couple of convenient methods such as: shutdown and internal ensureSocketIsOpen:

/**
 * Create a client for submitting signed transactions to underlying Cardano chain.
 *
 * @category Constructor
 **/
export const createTxSubmissionClient = async (
  context: InteractionContext
): Promise<TxSubmissionClient> => {
  const { socket } = context
  return Promise.resolve({
    context,
    evaluateTx: (bytes) => {
      ensureSocketIsOpen(socket)
      return evaluateTx(context, bytes)
    },
    submitTx: (bytes) => {
      ensureSocketIsOpen(socket)
      return submitTx(context, bytes)
    },
    shutdown: () => new Promise(resolve => {
      ensureSocketIsOpen(socket)
      socket.once('close', resolve)
      socket.close()
    })
  } as TxSubmissionClient)
}

So, I'm hitting the limit for a legitimate reason in this case and just need to increase (the default value is 10) the maximum listener value, or there is something else underneath we should care about?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingclient/TypeScriptIssues which regard the TypeScript client

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions