apla / node-clickhouse

Yandex ClickHouse driver for nodejs
MIT License
216 stars 50 forks source link

node-clickhouse fails silently when used with "pipeline". #76

Open paeolo opened 3 years ago

paeolo commented 3 years ago

It's a common thing when dealing with streams to wrap them with a pipeline like so:

const { pipeline } = require('stream');
const { promisify } = require('util');
const ClickHouse = require('@apla/clickhouse');

const ch = new ClickHouse({ host, port, user, password });

let input = SOME_INPUT_STREAM;
let output = ch.query("SOME_QUERY");

await promisify(pipeline)([
    input,
    output
]);

There is a big issue here when using @apla/clickhouse, because in case of error the output stream will emit the finish event before the error event, so the promise will resolve (ie. will not reject).

So basically using @apla/clickhouse with pipeline will cause errors to fail silently!

To fix this issue the stream created by @apla/clickhouse query function should finish after having errored I guess.