Node.js 24/26: an insert from a raw-format stream of non-ASCII strings stops and times out
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- backend-api-design
Research direction
Read packages/client-node/src/utils/encoder.ts and compare how NodeValuesEncoder.encodeValues handles raw streams with the Buffer handling in mapStream. Then inspect pipeStream in packages/client-node/src/connection/socket_pool.ts and run the reproduction with Node.js 24.22+ using a non-ASCII string stream and a Buffer stream. Done means raw-format string streams complete and insert all rows without regressing Buffer streams.
Written by the indexing model from the issue text.
Description
Describe the bug
With Node.js 24.22+ and 26.9+, insert() from a stream that is not in object mode (CSV, TabSeparated, CustomSeparated, and the other raw formats) stops sending the request body when the stream emits strings with non-ASCII text. The insert fails with a timeout, and no rows are written. A stream emits strings when it has an encoding, for example fs.createReadStream(path, 'utf8') or stream.setEncoding('utf8').
This is the stall of #1149, on the path that #1148 did not change: #1148 sends Buffers only for object-mode (JSON) streams.
- A stream of many small string chunks stops after about 64 KiB, also with a local server.
fs.createReadStream(path, 'utf8')(64 KiB chunks) completes with a local server. Behind a slow link (a TCP proxy at about 1.6 MB/s, as with a remote server), it stops after about 2.8 MB, and the server closes the request afterhttp_receive_timeout.- Not affected: the same data without an encoding (Buffers), ASCII text,
compression: { request: true }, Node.js 22.
Root cause: NodeValuesEncoder.encodeValues returns a stream that is not in object mode unchanged (packages/client-node/src/utils/encoder.ts:24-26), and pipeStream pipes it into http.ClientRequest (packages/client-node/src/connection/socket_pool.ts:417). With Node.js 24.22+ and 26.9+, a ClientRequest that gets non-ASCII strings waits for a 'drain' event that does not come (nodejs/node#66781; the fix nodejs/node#66782 is not in a 24.x or 26.x release yet). With request compression, the compressor gives the request Buffers, so the stall does not occur.
The fix is small: give the request Buffers for a raw-format stream too, as mapStream does since #1148.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Steps to reproduce
- Run the program below with Node.js 24.22.3 or 26.13.1.
- The insert from the string stream fails after
request_timeout(10 s). The same lines as Buffers insert at once.
Expected behaviour
All 100,000 rows are inserted, as with Node.js 22, and as with the same lines as Buffers.
Code example
Reproduction program (ES module, 32 lines)
import { createClient } from '@clickhouse/client'
import Stream from 'node:stream'
const client = createClient({
url: process.env.CLICKHOUSE_URL ?? 'http://localhost:8123',
request_timeout: 10_000,
})
await client.command({
query: 'CREATE OR REPLACE TABLE raw_str (id UInt32, s String) ENGINE = MergeTree ORDER BY id',
})
const lines = Array.from({ length: 100_000 }, (_, i) => `${i},"ééééé-${i}"\n`)
for (const [name, values] of [
// a non-object-mode stream with an encoding emits strings
['strings', Stream.Readable.from(lines, { objectMode: false }).setEncoding('utf8')],
// contrast: the same lines as Buffers
['Buffers', Stream.Readable.from(lines, { objectMode: false })],
]) {
await client.command({ query: 'TRUNCATE TABLE raw_str' })
const start = Date.now()
try {
await client.insert({ table: 'raw_str', values, format: 'CSV' })
console.log(process.version, name, 'ok', Date.now() - start, 'ms')
} catch (e) {
console.log(process.version, name, 'error:', e.message, Date.now() - start, 'ms')
}
const rs = await client.query({ query: 'SELECT count() AS c FROM raw_str', format: 'JSONEachRow' })
console.log(process.version, name, 'rows:', (await rs.json())[0].c)
}
await client.command({ query: 'DROP TABLE raw_str' })
await client.close()
Error log
Program output (the log lines of the client are not shown):
v22.23.5 strings ok 159 ms
v22.23.5 strings rows: 100000
v24.22.3 strings error: Timeout error. 10013 ms
v24.22.3 strings rows: 0
v24.22.3 Buffers ok 90 ms
v24.22.3 Buffers rows: 100000
v26.13.1 strings error: Timeout error. 10014 ms
v26.13.1 strings rows: 0
v26.13.1 Buffers ok 88 ms
v26.13.1 Buffers rows: 100000
At the stall (Node.js 24.22.3 and 26.13.1), ClientRequest.write() got 2,934 strings and returned false once, at 65,262 bytes. Then the request has writableNeedDrain: true and writableLength: 0, its socket has writableNeedDrain: false, and the source stream stays paused.
fs.createReadStream(path, 'utf8') with 10.6 MB of the same rows, behind the slow link, Node.js 24.22.3 and 26.13.1 (Node.js 22, and the same file without an encoding, complete in 6.7 s):
Timeout exceeded while reading from socket (peer: [::ffff:127.0.0.1]:33224, local: [::ffff:127.0.0.1]:8123, 30000 ms).
Configuration
Environment
- Client version:
mainat 299e128 (package version 1.25.0; release 1.25.0 has the same code) - Language version: Node.js 24.22.3 and 26.13.1 (affected), 22.23.5 (not affected)
- OS: Linux (Docker)
ClickHouse server
- ClickHouse Server version: 26.11.4.11
- ClickHouse Server non-default settings, if any: none
Classification: impact: Stability · area: Queries (streaming inserts)
Found by automated analysis (Polyglot AI) while working on the review skill of #1185. Verified against a live server.
- Dominant language
- TypeScript
- Stars
- 332
- Forks
- 94
- Avg merge
- 19h 15m
- Merged PRs (30d)
- 43
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ClickHouse/clickhouse-js
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1292 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1290 ·
Maintainers usually reply within 1 day
-
bug data-types documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-js#1282 ·
Maintainers usually reply within 1 day
-
Core SQL test harness: the shim takes the next setting as the value of --allow_repeated_settingsPossibly taken @polyglotAI-bot claimed this 3 days ago. Opentests
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1266 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in ClickHouse/clickhouse-js
Similar issues
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day
-
area/docs framework/jekyll language/markdown
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
meshery/schemas#1456 · 1 comment ·
Maintainers usually reply within 1 day