Repository navigation
fix(common-utils): run at most four filter value reads at once per connection - #3901
Conversation
…nnection The search filter panel started every text index values batch together, so on a slow service one page load held about ten proxy sockets per Map column for the whole read. Queue the rest, and drop queued reads whose signal aborted. HDX-6272
🦋 Changeset detectedLatest commit: 6fff982 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| return async <T>(task: () => Promise<T>): Promise<T> => { | ||
| if (active < max) active++; | ||
| // The finishing task hands its slot straight over, so `active` is unchanged. | ||
| else await new Promise<void>(resolve => waiting.push(resolve)); |
There was a problem hiding this comment.
🟡 P2 — An aborted read stays in the queue and only settles once some other read frees a slot
In createLimiter, also accept the signal: when it fires, remove the waiter from waiting and reject it right away, instead of calling throwIfAborted only after the task is dequeued. As written, an aborted waiter sits in waiting until an unrelated read finishes. That read may belong to another caller with its own signal, and the limiter is process-wide in the API. So describe_source (packages/api/src/mcp/tools/sources/describeSource.ts:358/407), which awaits getAllKeyValues after its budget aborts, keeps hanging for up to a full read (12–20s per the PR description). The handler outlives its deadline even though no query will be sent.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 1 P3 1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom. 🔵 1 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6fff982. Configure here.
| // The node client ignores a signal that aborted before the query starts. | ||
| signal?.throwIfAborted(); | ||
| return task(); | ||
| }); |
There was a problem hiding this comment.
Abort check misses pre-query await
Medium Severity
limitTextIndexRead calls throwIfAborted and then clickhouseClient.query, but the node client only receives abort_signal after processClickhouseSettings awaits getSettings. An abort during that await is ignored, so the read still runs and keeps its limiter slot and proxy socket.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6fff982. Configure here.
| return result.data.map(row => ({ | ||
| key: `${row.column}['${row.key}']`, | ||
| value: row.value, | ||
| })); |
There was a problem hiding this comment.
Queued abort fails shared fetch
Medium Severity
The queued throwIfAborted runs inside the getOrFetch callback, whose cache key does not include signal. An abort rejects that shared pending promise, and the catch resolves it as undefined, so another caller waiting on the same key gets no values even if its own signal is still active.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6fff982. Configure here.
Deep Review✅ No critical issues found. The concurrency primitive is sound — the correctness reviewer traced 🟡 P2 — recommended
🔵 P3 nitpicks (6)
Reviewers (11): correctness, adversarial, performance, reliability, kieran-typescript, testing, maintainability, project-standards, agent-native, learnings-researcher, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 498 passed • 1 skipped • 1093s
Tests ran across 4 shards in parallel. |


Summary
The search page filter sidebar now runs at most four text index value reads at once per connection, instead of starting every batch together. On a slow service, one page load used to keep about ten
/clickhouse-proxyrequests open per Map column for 12-20s each. One user with nine search tabs open pushed everyhyperdx-apipod in a prod ReplicaSet over theHyperDXAPI-App-HighSocketHandlesalert.describe_sourcetime budget would let queued reads run to completion.How to reproduce
Starting point:
yarn devagainst a ClickHouse service where a log source'sLogAttributesMap column has a text index (for exampleidx_log_attr_items), with enough data that the value reads take a few seconds.On
main:clickhouse-proxy.mergeTreeTextIndex: about ten are pending at once per Map column.On this branch:
How to test on Vercel preview
N/A, non-UI change. The sidebar looks the same; only request concurrency changes.
Implementation detail
connectionIdbecause each hook builds its ownMetadatainstance against the same connection. A per-instance limit would not bound anything.res.json(), so the slot is held until the response body has been read.MetadataCache.getOrFetch, so duplicate requests are still deduped before they queue.References
Note
Medium Risk
Concurrency change on a hot metadata path that affects proxy socket usage and query timing, but behavior is additive (queue + abort) with no API or schema changes.
Overview
Caps concurrent filter-sidebar text index value reads at four per
connectionId(per browser tab or API process), instead of firing every batch at once. A module-levelcreateLimiterqueue wraps map- and native-mergeTreeTextIndexreads ingetAllKeyValues, holding the slot through query execution and response parsing so proxy sockets aren't piled up on slow services.Queued reads honor
AbortSignal:throwIfAborted()runs when a task dequeues, so aborted requests never hit ClickHouse. Filter values still stream in as reads complete—later batches start when slots free up. Tests assert at most four in-flight reads for 60 keys and that abort after four starts prevents further reads.Reviewed by Cursor Bugbot for commit 6fff982. Bugbot is set up for automated code reviews on this repo. Configure here.