Skip to content

Reproductible ERR_INTERNAL_ASSERTION on node 15 #38189

Closed
@Congelli501

Description

@Congelli501

What steps will reproduce the bug?

I had a ERR_INTERNAL_ASSERTION when trying to run our application using node 15.x, for a stream destroy test. This code is the minimal version to reproduce it.
The code works ok on node 14.16.1, but fails under node 15.14.0

'use strict';

const {pipeline: pipelineCb, Writable, Readable} = require('stream');
const util = require('util');
const pipeline = util.promisify(pipelineCb);

(async () => {
	// Create a dummy readable stream
	let i = 0;
	const readable = new Readable({
		objectMode: true,
		read () {
			this.push({counter: i++});
		}
	});

	// Create a dummy writable stream with backpressure
	const writable = new Writable({
		objectMode: true,
		write: (chunk, encoding, callback) => {
			setTimeout(callback, 10); // Backpressure
		}
	});

	// Pipeline the sql stream in the dummy writable stream & destroy the writable stream after a few ms
	try {
		await Promise.all([
			pipeline(readable, writable),
			(async () => {
				// Destroy the stream after a few element
				// pipeline will destroy all the streams
				await new Promise(resolve => setTimeout(resolve, 50));
				writable.destroy();
			})()
		]);
	} catch (e) {
		if (e.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
			throw e;
		}
	}
})().catch(e => {
	console.error(e);
	process.exitCode = 1;
});

To reproduce (under node 15):

% node index.js
node:internal/assert:14
    throw new ERR_INTERNAL_ASSERTION(message);
    ^

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:329:5)
    at assert (node:internal/assert:14:11)
    at Writable.destroy (node:internal/streams/writable:851:5)
    at Object.destroyer (node:internal/streams/destroy:365:59)
    at node:internal/streams/pipeline:73:17
    at finish (node:internal/streams/pipeline:159:23)
    at node:internal/util:408:5
    at node:internal/streams/pipeline:74:5
    at finish (node:internal/streams/pipeline:159:23)
    at node:internal/util:408:5 {
  code: 'ERR_INTERNAL_ASSERTION'
}

Expected behavior (under node14):

% node index.js
<no output>

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions