Repository navigation
fix: stop leaking Elasticsearch scroll contexts - #218
Merged
Merged
Conversation
The index-ids handler held a 5m scroll context per request and cleared it with the request context, so a client disconnect left the context open until it expired. A burst of these counts against search.max_open_scroll_context (500), after which every scroll user, including _delete_by_query, fails with "Trying to create too many scroll contexts". Page with a point in time and search_after on meta.hubID (as the sitemap and Stream already do), keepalive 1m, and close the point in time with a context detached from the request. Output, per-page flushing and the 500-only-before-the-first-id behaviour are unchanged. The paging loop is split out as writeIndexIDs and unit tested without Elasticsearch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetPreviousScrollIDs returned from inside its scroll loop (match found, end of results, or error) without clearing the scroll, so every call left a 5m scroll context behind. Clear it in a defer with a background context and lower the keepalive to 1m. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #218 +/- ##
==========================================
+ Coverage 36.08% 36.10% +0.01%
==========================================
Files 412 412
Lines 38113 38154 +41
==========================================
+ Hits 13753 13775 +22
- Misses 24358 24377 +19
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Incident
On 2026-11-04 around 06:00 the acpt Elasticsearch reached
search.max_open_scroll_context(500). Every scroll user then failed withTrying to create too many scroll contexts, including hub3/api/admin/index-idsand the v1_delete_by_query. The open contexts were 5m-keepalive scrolls created in a burst. We have not yet confirmed which caller created them. This PR fixes the two hub3 code paths that can leave scroll contexts open.Changes
ikuzo/service/x/bulk/handle_ids.go: index-ids now pages with a point in time instead of a scrollelasticsearch.PITClient(CreatePIT/ClosePIT, which also handles OpenSearch) with a 1m keepalive, then pages withsearch_aftersorted onmeta.hubID, the same approach asstreamWithPITand the sitemap. PIT contexts don't count againstmax_open_scroll_context.context.WithoutCancel(r.Context())with a 10s timeout. A client disconnect therefore no longer stops the cleanup. Before this change,scroll.Clear(r.Context())failed on disconnect and the context stayed open for 5 minutes.writeIndexIDs(w, fetch)so it can be unit tested without ES (handle_ids_test.go).hub3/fragments/resource.go:GetPreviousScrollIDsalways clears its scrollio.EOF, error) used to return from inside the loop without clearing the scroll. Each tree-navigation call therefore left a 5m context open. ES keeps a scroll open even after it returns the empty last page.scroll.Clearnow runs in a defer with a background context and a 10s timeout, and the keepalive is set explicitly to1m. Nothing else changes.ES-internal scrolls from
_delete_by_queryare left as they are.Tests
go build ./...: OKgo vet ./ikuzo/service/x/bulk/ ./hub3/fragments/: OKgo test ./ikuzo/service/x/bulk/: OK, 12 top-level tests pass, including the newTestWriteIndexIDs(paging,search_afterpropagation, skipping hits without a hubID, flushing) andTestWriteIndexIDsErrorAfterFirstPage.go test ./hub3/fragments/: 57 top-level tests pass and 1 is skipped (Test_TypeClassAsURI, skipped already on main). The Ginkgo suiteTestFragments(99 specs) fails inBeforeSuitebecause Docker isn't available in this environment for testcontainers:get provider: check host "unix:///var/run/docker.sock": docker info: permission denied. This is an environment problem and not caused by this change. It still needs a run where Docker is available.GetPreviousScrollIDs. Please verify on acpt after deploy, for example withGET _nodes/stats/indices/search(open_contexts/scroll_current) while calling index-ids and aborting the request partway.🤖 Generated with Claude Code