Race condition when running ES delete_by_query #13562

Closed
opened 2025-11-02 10:46:07 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @bsofiato on GitHub (Oct 3, 2024).

Description

When running the unit test associated with code search (file modules/indexer/code/indexer_test.go), I ran into the issue in the screenshot below.

image

As explained here, this is due to a racing condition where ES uses an outdated index while looking for the documents to delete. The safe approach is to ask ES to refresh the index before.

I wrote a PR that changes the behavior when trying to delete the documents of a repo. If the deletion results in a conflict, Gitea will refresh the index and retry.

P.S. ES is running inside a docker container spun by the command below:

docker run --rm --memory="4g" -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e "discovery.type=single-node" -v "$(pwd)/data/elasticsearch:/usr/share/elasticsearch/data" docker.elastic.co/elasticsearch/elasticsearch:7.16.3

Gitea Version

0b1b4030e6

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

I ran into this issue while running the tests inside VSCode

Database

None

Originally created by @bsofiato on GitHub (Oct 3, 2024). ### Description When running the unit test associated with code search (file modules/indexer/code/indexer_test.go), I ran into the issue in the screenshot below. ![image](https://github.com/user-attachments/assets/46c3747e-7b06-43ba-94b3-a3fb957775d0) As explained [here](https://discuss.elastic.co/t/elasticsearch-delete-by-query-409-version-conflict/174150), this is due to a racing condition where ES uses an outdated index while looking for the documents to delete. The safe approach is to ask ES to refresh the index before. I wrote a PR that changes the behavior when trying to delete the documents of a repo. If the deletion results in a conflict, Gitea will refresh the index and retry. P.S. ES is running inside a docker container spun by the command below: ``` docker run --rm --memory="4g" -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e "discovery.type=single-node" -v "$(pwd)/data/elasticsearch:/usr/share/elasticsearch/data" docker.elastic.co/elasticsearch/elasticsearch:7.16.3 ``` ### Gitea Version 0b1b4030e66b1312fc9c0270f128bcf368f14178 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? I ran into this issue while running the tests inside VSCode ### Database None
GiteaMirror added the type/bug label 2025-11-02 10:46:07 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13562