Skip to content

fix(indexer): recover from panic on corrupted issue index search#38212

Draft
bircni wants to merge 1 commit into
go-gitea:mainfrom
bircni:fix/issue-indexer-search-panic-38210
Draft

fix(indexer): recover from panic on corrupted issue index search#38212
bircni wants to merge 1 commit into
go-gitea:mainfrom
bircni:fix/issue-indexer-search-panic-38210

Conversation

@bircni

@bircni bircni commented Jun 25, 2026

Copy link
Copy Markdown
Member

Fixes #38210

Searching issues (GET /issues?...&q=...) can panic with runtime error: index out of range [N] with length N, crashing the request with a 500 panic page. The panic originates in the Bleve zapx storage engine while decoding a term posting list (zapx/v17/memuvarint.go ReadUvarint, which reads S[C] with no bounds check), indicating a corrupted on-disk issue index segment.

Regression

This surfaced after #37525, which bumped bleve v2.5.7 -> v2.6.0 and introduced zapx/v17 v17.1.2 — the exact version in the reported stack trace. The new v17 segment format is what panics on the corrupt posting list. Bumping the dependency does not help: memuvarint.go is byte-for-byte identical in the current v17.1.6, so the missing bounds check is still upstream.

Change

The init path already recovers from corruption panics and logs guidance to rebuild the index, but the search path had no recover(). This wraps the Bleve search in searchWithPanicRecover, converting a panic into a returned error and logging the rebuild hint, so a single corrupted segment degrades that search instead of crashing the request. A regression test covers the wrapper.

Operators still need to rebuild the index (delete ISSUE_INDEXER_PATH and restart) to clear the corruption.

Authored with assistance from Claude Code (Opus 4.8).

A corrupted on-disk bleve index makes the underlying zapx search panic
with "index out of range" while decoding a posting list, crashing the
GET /issues request with a 500 panic page (go-gitea#38210). Wrap the bleve
search in a recover() that converts the panic into an error and logs
guidance to rebuild the index, mirroring the existing init-time
handling. Add a regression test for the recovery wrapper.

Assisted-by: Claude Code:claude-opus-4-8
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 25, 2026
@bircni bircni requested a review from puni9869 June 25, 2026 11:11
@bircni bircni added this to the 1.27.0 milestone Jun 25, 2026

// searchWithPanicRecover runs a bleve search and converts any panic into an
// error. A corrupted on-disk index (e.g. a truncated zapx posting list) makes
// the underlying bleve search panic with "index out of range" (see #38210);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When any index changed we reindex the model. I did not understood why it got paniced.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 25, 2026
@wxiaoguang

Copy link
Copy Markdown
Contributor
  • I guess end user still sees 500 error page, so no difference with or without this change.
  • If you'd really really like to "wrap", searchWithPanicRecover is a general util function and should be in util package.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 25, 2026
@wxiaoguang wxiaoguang marked this pull request as draft June 25, 2026 23:04
@wxiaoguang

Copy link
Copy Markdown
Contributor

I don't think it is good to merge. #38212 (comment)

And, ideally, the bug should be fixed by upstream, but not by the Gitea side patch.

@bircni bircni modified the milestones: 1.27.0, 1.28.0 Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bleve search zapx: index out of range

5 participants