Skip to content

Promise.race lead to memory leak #17469

Closed
@win-t

Description

@win-t
  • Version: v9.2.0 and v8.9.1, probably other version also affected
  • Platform: linux
  • Subsystem: -

I run this code inside docker with -m 100m --memory-swap 100m , and then the program crash after few second

function doWork() {
    // ... do real work with some sleep at the end, but for demo purpose i just return (async) resolved promise
    return new Promise(a => setImmediate(a));
}

var exit = false;
const exitPromise = new Promise(a => {
    process.once('SIGINT', () => {
        exit = true;
        a();
    });
});

(async () => {
    console.log('start');
    while(!exit) {
        await Promise.race([exitPromise, doWork()]);
    }
    console.log('stop');
})().catch(console.error.bind(console));

but it perfectly fine when i change await Promise.race([exitPromise, doWork()]); with await doWork();

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidIssues and PRs that are invalid.memoryIssues and PRs related to the memory management or memory footprint.promisesIssues and PRs related to ECMAScript promises.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions