Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
killagu opened this issue May 10, 2023 · 0 comments · Fixed by #47949
Closed

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

killagu opened this issue May 10, 2023 · 0 comments · Fixed by #47949

Comments

@killagu
Copy link
Contributor

killagu commented May 10, 2023

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

killagu added a commit to killagu/node that referenced this issue May 10, 2023
killagu added a commit to killagu/node that referenced this issue May 10, 2023
killagu added a commit to killagu/node that referenced this issue May 10, 2023
@tniessen tniessen changed the title processs.stdout may memleak if write file failed. process.stdout may memleak if write file failed. May 10, 2023
killagu added a commit to killagu/node that referenced this issue May 11, 2023
killagu added a commit to killagu/node that referenced this issue May 11, 2023
killagu added a commit to killagu/node that referenced this issue May 14, 2023
killagu added a commit to killagu/node that referenced this issue May 14, 2023
killagu added a commit to killagu/node that referenced this issue Jun 26, 2023
killagu added a commit to killagu/node that referenced this issue Jun 26, 2023
killagu added a commit to killagu/node that referenced this issue Jun 26, 2023
Catch SyncWriteStream write file error.

Fixes: nodejs#47948
Signed-off-by: killagu <killa123@126.com>
nodejs-github-bot pushed a commit that referenced this issue Jun 26, 2023
Catch SyncWriteStream write file error.

Fixes: #47948
Signed-off-by: killagu <killa123@126.com>
PR-URL: #47949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
RafaelGSS pushed a commit that referenced this issue Jul 3, 2023
Catch SyncWriteStream write file error.

Fixes: #47948
Signed-off-by: killagu <killa123@126.com>
PR-URL: #47949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
Catch SyncWriteStream write file error.

Fixes: nodejs#47948
Signed-off-by: killagu <killa123@126.com>
PR-URL: nodejs#47949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
Catch SyncWriteStream write file error.

Fixes: nodejs#47948
Signed-off-by: killagu <killa123@126.com>
PR-URL: nodejs#47949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
ruyadorno pushed a commit that referenced this issue Sep 10, 2023
Catch SyncWriteStream write file error.

Fixes: #47948
Signed-off-by: killagu <killa123@126.com>
PR-URL: #47949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
ruyadorno pushed a commit that referenced this issue Sep 13, 2023
Catch SyncWriteStream write file error.

Fixes: #47948
Signed-off-by: killagu <killa123@126.com>
PR-URL: #47949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant