Skip to content

Node alpine images return exit code 0 after dead because of OOM #1340

Open
@yoga1982

Description

@yoga1982

Hi,
I'm using image node:12.18.3-alpine in my project for executing background jobs. Recently I found when Node exit because of OOM, the exit code is 0, so other program cannot catch exception of the jobs.
I also prepared some test code for simulate the scenario.
script ==> test.js

"use strict";
const list = [];
setInterval(() => {
  const record = new MyRecord();
  list.push(record);
}, 0.000001);
function MyRecord() {
  var x = "hii";
  this.name = x.repeat(100000000);
  this.id = x.repeat(100000000);
  this.account = x.repeat(100000000);
}
setInterval(() => {
  console.log(process.memoryUsage());
}, 100);

package.json

{
  "name": "memory_test",
  "version": "1.0.0",
  "description": "",
  "main": "test.js",
  "scripts": {
    "oom": "node --throw-deprecation --max-old-space-size=1 test.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

to run test.js

docker run --name oom_test -v <same folder with package.json>:/app -it node:12.18.3-alpine sh -c 'cd /app; npm run oom'

to check Exit Code ==> "ExitCode": 0,

docker inspect oom_test |grep ExitCode

if i change image to node:12.18.3, exit code would be correct ==> "ExitCode": 134,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions