Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsdb/index/postings: fix missing lock unlock #14103

Merged

Conversation

krajorama
Copy link
Member

Followup to #14096

Unfortunately the previous PR introduced this bug by not releasing the lock before returning.

Followup to prometheus#14096

Unfortunately the previous PR introduced this bug by not releasing the
lock before returning.

Signed-off-by: György Krajcsovits <[email protected]>
@krajorama krajorama marked this pull request as ready for review May 15, 2024 12:03
Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Could we just do defer p.mtx.RUnlock() in line 402?

@krajorama
Copy link
Member Author

Could we just do defer p.mtx.RUnlock() in line 402?

I suspect it's not done that way because of line 431, the last return

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Ah, right, we need to release it before executing Merge. Too bad…

@beorn7 beorn7 merged commit 179163a into prometheus:main May 15, 2024
25 checks passed
@pstibrany
Copy link
Contributor

pstibrany commented May 15, 2024

We could unlock by default in defer, and skip unlock in defer when not needed.

	unlockInDefer := true
	defer func() {
		if unlockInDefer {
			p.mtx.RUnlock()
		}
	}()

and set unlockInDefer = false where required.

(We use this pattern in few places in Mimir.)

@beorn7
Copy link
Member

beorn7 commented May 15, 2024

Hmm, not sure what is less bad… it's both error prone, but the current solution is still a bit more compact (which would change if we had more exit points).

krajorama added a commit to grafana/mimir that referenced this pull request May 15, 2024
grafanabot pushed a commit to grafana/mimir that referenced this pull request May 15, 2024
krajorama added a commit to grafana/mimir that referenced this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants