break inside a for await doesn't close the connection
tobia opened this issue · 0 comments
tobia commented
If you try this code in a node console:
const { ClickHouse } = require('clickhouse')
const ch = new ClickHouse({ url: 'http://localhost:8123' })
async function test() {
let i = 0;
for await (const rs of ch.query('select number from system.numbers').stream()) {
if (++i > 3) break;
console.log(rs.number);
}
}
You get the expected results:
> test()
> 1
2
3
But if you monitor the open connections with netstat -tn | grep 8123
you will see that every time you call test()
it opens a new connection to port 8123 and leaves it hanging.
I looked into the code of stream2asyncIter and I see that destroy() is actually called by the for-async-break, but then the code looks for a this.close (which doesn't exist) and does nothing else.
I think the stream2asyncIter destroy() should call stream.destroy()
on the original stream, and then the original stream "rs" should receive destroy() and close the HTTP stream.
No?