Skip to content

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

Merged
beorn7 merged 1 commit intoprometheus:mainfrom
krajorama:handle-context-cancel-in-postingsformatcher
May 15, 2024
Merged

tsdb/index/postings: fix missing lock unlock#14103
beorn7 merged 1 commit intoprometheus:mainfrom
krajorama:handle-context-cancel-in-postingsformatcher

Conversation

@krajorama
Copy link
Copy Markdown
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
@krajorama krajorama requested a review from jesusvazquez as a code owner May 15, 2024 12:03
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@pstibrany
Copy link
Copy Markdown
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
Copy Markdown
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