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

worker: flush stdout and stderr on exit #56428

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@
chunks: ArrayPrototypeMap(chunks,
({ chunk, encoding }) => ({ chunk, encoding })),
});
if (process._exiting) {
cb()

Check failure on line 296 in lib/internal/worker/io.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
}
ArrayPrototypePush(this[kWritableCallbacks], cb);
mcollina marked this conversation as resolved.
Show resolved Hide resolved
if (this[kPort][kWaitingStreams]++ === 0)
this[kPort].ref();
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-worker-stdio-flush.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');

Check failure on line 4 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'fs' is assigned a value but never used
const util = require('util');

Check failure on line 5 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'util' is assigned a value but never used
const { Writable } = require('stream');

Check failure on line 6 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'Writable' is assigned a value but never used
const { Worker, isMainThread } = require('worker_threads');

if (isMainThread) {
const w = new Worker(__filename, { stdout: true });
const expected = 'hello world'

Check failure on line 11 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon

let data = ''

Check failure on line 13 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
w.stdout.setEncoding('utf8')

Check failure on line 14 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
w.stdout.on('data', (chunk) => {
data += chunk

Check failure on line 16 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
})

Check failure on line 17 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon

w.on('exit', common.mustCall(() => {
assert.strictEqual(data, expected)

Check failure on line 20 in test/parallel/test-worker-stdio-flush.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
}));
} else {
process.on('exit', () => {
process.stdout.write(' ')
process.stdout.write('world')
})
process.stdout.write('hello')
}
Loading