Skip to content

Conversation

Alhanaqtah
Copy link
Contributor

Fixing panic caused by unlocking unlocked mutex.

Fixed #16318

@Alhanaqtah Alhanaqtah changed the title fix: unlock on unlocked mutex fix: unlock of unlocked mutex Mar 27, 2025
@Alhanaqtah Alhanaqtah requested a review from colega March 27, 2025 21:44
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

@aknuds1
Copy link
Contributor

aknuds1 commented Mar 29, 2025

@Alhanaqtah Can you sign your commits please? We can't merge before that's taken care of, this is why the DCO check is failing.

@Alhanaqtah Alhanaqtah requested a review from aknuds1 March 30, 2025 11:41
@aknuds1
Copy link
Contributor

aknuds1 commented Mar 30, 2025

You have to sign all of your commits. Maybe just squash them into one, signed, commit?

Signed-off-by: Usama Alhanaqtah <a.usama@yandex.ru>
@Alhanaqtah Alhanaqtah force-pushed the fix-unlock-of-unlocked-mutex branch from 4c0fd99 to f7eaaf5 Compare March 30, 2025 20:23
@colega
Copy link
Contributor

colega commented Mar 31, 2025

IMO this change could use a test, otherwise there's nothing preventing it from happen again.

@Alhanaqtah
Copy link
Contributor Author

IMO this change could use a test, otherwise there's nothing preventing it from happen again.

Is there any conventions or guidelines for writing test?

@colega
Copy link
Contributor

colega commented Apr 1, 2025

You can check head_test.go and db_test.go files for the existing tests, there should be some that exercise this path, but they don't exercise the error case.

@github-actions github-actions bot added the stale label May 31, 2025
Copy link
Member

@jesusvazquez jesusvazquez left a comment

Choose a reason for hiding this comment

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

@Alhanaqtah your code changes look good but as @colega pointed out we're missing a unit test. I can give you some pointers.

  • func TestHeadAppender_AppendCT(t *testing.T) {
    func TestHeadAppender_AppendCT(t *testing.T) {
    is a good example, you can duplicate this test to test that errors are handled properly.
  • Originally the appendableHistogram functions did not return other types of errors other than ErrOutOfOrderSample this why we got to this situation. However now they can return ErrDuplicateSampleForTimestamp ErrTooOldSample ErrOutOfBounds and ErrOutOfOrderSample. So for example I think that if you attempt two AppendHistogramCTZeroSample calls with the same values you should be getting ErrDuplicateSampleForTimestamp from appendableHistogram and your new return clauses should be executed.

Are you up for this quick test?

@github-actions github-actions bot removed the stale label Jun 2, 2025
@Alhanaqtah
Copy link
Contributor Author

@jesusvazquez thanks for the pointers. They are very helpful) Yeah, i'll write tests

Signed-off-by: Usama Alhanaqtah <a.usama@yandex.ru>
@Alhanaqtah Alhanaqtah requested a review from jesusvazquez June 4, 2025 18:06
Copy link
Contributor

@colega colega left a comment

Choose a reason for hiding this comment

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

Thanks, I checked that the test panics without the fix.

@Alhanaqtah
Copy link
Contributor Author

@jesusvazquez could you approve PR, please?

@krajorama
Copy link
Member

krajorama commented Jul 9, 2025

I've just ran into this bug when I triggered duplicate sample error in grafana/mimir#11977
I used the same fix before finding this PR :)

Copy link
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

LGTM. I'd prefer a few more testcases, but I can add mine later.

Copy link
Member

@jesusvazquez jesusvazquez left a comment

Choose a reason for hiding this comment

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

Thank you for the PR and the tests.

@jesusvazquez jesusvazquez merged commit 89f011b into prometheus:main Jul 9, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fatal error: sync: unlock of unlocked mutex
5 participants