I'm experiencing a recurring "socket hang up" error when using ClickHouse with Node.js, and I'm hoping to understand how to reproduce and fix it. Here are the details:
ClickHouse version: 23.6.2.18
Node.js version: v20.12.2
Logs:
48|app | 06-01-2025 15:51:52:
48|app | 06-01-2025 15:51:52: Error: socket hang up
48|app | 06-01-2025 15:51:52: at connResetException (node:internal/errors:787:14)
48|app | 06-01-2025 15:51:52: at Socket.socketCloseListener (node:_http_client:468:25)
48|app | 06-01-2025 15:51:52: at Socket.emit (node:events:530:35)
48|app | 06-01-2025 15:51:52: at TCP.<anonymous> (node:net:337:12) {
48|app | 06-01-2025 15:51:52: code: 'ECONNRESET'
48|app | 06-01-2025 15:51:52: }
This error repeats multiple times and then the process resumes.
What I suspect:
- The error is happening during an
OPTIMIZE
query to ClickHouse. ECONNRESET
typically indicates that the server closed the connection abruptly, but I can't identify why.
Any insights or troubleshooting tips would be greatly appreciated! Thank you!
Code:
async.each(resp.rows, function(row, callback) {
let PId = row.id;
let optimizeQuery = `OPTIMIZE TABLE ${table} PARTITION ${PId} FINAL`;
ch.query(optimizeQuery, (errOptimize, optimizeDone) => {
if (errOptimize) {
return callback(errOptimize);
} else {
callback();
}
});
}, function(err) {
if (err) {
reject({'ack': 'Failure'});
} else {
resolve({'ack': 'Success'});
}
});
What I've tried:
- Verified that ClickHouse is up and running during the error.
- Checked network stability.
- Increased connection and query timeouts.
- Reduced batch sizes (though it's still happening even at 100k rows).
Questions:
- How can I reliably reproduce this socket hang-up error with ClickHouse and Node.js?
- What could cause ClickHouse to abruptly terminate the connection during an
OPTIMIZE
query? - Are there best practices for keeping ClickHouse connections stable with large batch operations?
Any help or pointers would be amazing!