te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Facing a 'socket hang up' issue while executing a query on ClickHouse in a Node.js application - St
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Facing a 'socket hang up' issue while executing a query on ClickHouse in a Node.js application - St

programmeradmin3浏览0评论

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:

  1. How can I reliably reproduce this socket hang-up error with ClickHouse and Node.js?
  2. What could cause ClickHouse to abruptly terminate the connection during an OPTIMIZE query?
  3. Are there best practices for keeping ClickHouse connections stable with large batch operations?

Any help or pointers would be amazing!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论