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

ERR_INTERNAL_ASSERTION with node 15 #1314

Closed
Congelli501 opened this issue Apr 8, 2021 · 1 comment
Closed

ERR_INTERNAL_ASSERTION with node 15 #1314

Congelli501 opened this issue Apr 8, 2021 · 1 comment

Comments

@Congelli501
Copy link
Contributor

Hi,
We have an api that can stream from the db to the end user, be we have issue with node 15 & if the stream is destroyed (the end user closes the connection).

Here is a code used to reproduce the issue:

'use strict';

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

const mysql = require('mysql2/promise');

/**
 * Main
 * @returns {Promise<void>}
 */
async function main () {
	const pool = await mysql.createPool({
		host: '127.0.0.1',
		user: 'root',
		database: 'db'
	});

	const connection = await pool.getConnection();

	// Create the sql stream, select a table with a few hundreds / thousands of row to ensure we have backpressure
	const sqlStream = connection.connection.query('SELECT * FROM myTable').stream();

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

	// Pipeline the sql stream in the dummy writable stream & close the writable stream after a few ms
	try {
		await Promise.all([
			pipeline(sqlStream, writable),
			(async () => {
				// Destroy the stream after a few element
				// pipeline will destroy destroy all the streams
				await new Promise(resolve => setTimeout(resolve, 50));
				writable.destroy();
			})()
		]);
	} catch (e) {
		assert.strictEqual(e.code, 'ERR_STREAM_PREMATURE_CLOSE');
	}

	await pool.end();
}

main().catch(e => {
	console.error(e);
	process.exitCode = 1;
});

The code will throw an ERR_INTERNAL_ASSERTION error

@Congelli501
Copy link
Contributor Author

Fixed with nodejs/node#38189

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

No branches or pull requests

1 participant