Skip to content

process.stdout may memleak if write file failed. #47948

Closed
@killagu

Description

@killagu

Version

= 14

Platform

Linux::5.15.49-linuxkit

Subsystem

fs

What steps will reproduce the bug?

Create a container with disk size is 1m.

docker run --tmpfs /run:rw,noexec,nosuid,size=1024k --entrypoint bash -ti --rm node:20-buster

Create a file named test.js.

// test.js
const util = require('util');
const fs = require('fs');
const crypto = require('crypto');

(async () => {
	while (true) {
		try {
			const content = util.format('%s%s\n', new Date(), crypto.randomBytes(1024 * 100).toString('hex'));
			process.stdout.write(content, err => {
				if (err) {
					console.error(err);
				}
			});
		} catch (e) {
			// will print 
			// write error:  Error: ENOSPC: no space left on device, write
			console.error('write error: ', e);
		}
		await new Promise((resolve) => {
			setTimeout(resolve, 100);
		});
	}
})();

Run it and rotate stdout to a file in the tmpfs.

node test.js > /run/test.log

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

It's the memory leak.

image

Additional information

No response

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