Skip to content

MemoryLeak due to long await in CertificateService issue method of @energyweb/origin-247-certificate package's causing, when trying to issue around 50 certificates  #3368

@Ahmed-Suhail

Description

@Ahmed-Suhail

Description

When using issue method of CertificateService of @energyweb/origin-247-certificate package, we are triggering this method to issue certificates in our system. This warning doesnt comes when we issue 2-5 certificates especially we try to issue more certificates like 50 we get the below warning

Warning in Console

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 global:completed listeners added to [Queue]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:475:17)
at Queue.addListener (events.js:497:10)
at Queue.on (/var/deployment/common/temp/node_modules/.pnpm/[email protected]/node_modules/bull/lib/queue.js:326:14)
at /var/deployment/common/temp/node_modules/.pnpm/[email protected]/node_modules/bull/lib/job.js:504:18
at new Promise ()
at Job.finished (/var/deployment/common/temp/node_modules/.pnpm/[email protected]/node_modules/bull/lib/job.js:480:12)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async CertificateService.waitForJobResult (/var/deployment/common/temp/node_modules/.pnpm/@energyweb[email protected]_a1b67e60083a0f64adab87445ef00c80/node_modules/@energyweb/origin-247-certificate/dist/js/src/certificate.service.js:111:20)
at async CertificateService.issue (/var/deployment/common/temp/node_modules/.pnpm/@energyweb[email protected]_a1b67e60083a0f64adab87445ef00c80/node_modules/@energyweb/origin-247-certificate/dist/js/src/certificate.service.js:48:24)
(node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 global:failed listeners added to [Queue]. Use emitter.setMaxListeners() to increase limit

Alernate Solution

We can have alternate method which doesnt awaits for the job to complete but just puts the job on queue and returns.
Due to long await waitForJobResult we are getting MemoryLeak

This is snippet in issue method of CertificateService of @energyweb/origin-247-certificate
const job = await this.blockchainActionsQueue.add({
payload: command,
type: types_1.BlockchainActionType.Issuance
}, jobOptions);
const result = await this.waitForJobResult(job);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions