Skip to content

ydb_topic: do not call lock_shared recursively#4366

Merged
qyryq merged 2 commits intoydb-platform:mainfrom
qyryq:ydb-topic-allow-recursive-lock-shared
May 8, 2024
Merged

ydb_topic: do not call lock_shared recursively#4366
qyryq merged 2 commits intoydb-platform:mainfrom
qyryq:ydb-topic-allow-recursive-lock-shared

Conversation

@qyryq
Copy link
Collaborator

@qyryq qyryq commented May 7, 2024

TCallbackContext::LockShared method creates a new TBorrowed object. Its constructor acquires a shared_lock on the mutex stored in the TCallbackContext object.

In a rare situation the LockShared method is called twice in a row from the same thread, but calling lock_shared more than once without releasing the lock leads to undefined behaviour (see https://en.cppreference.com/w/cpp/thread/shared_mutex/lock_shared).

In general, recursive mutexes are frowned upon, but in our case it looks to be the most elegant solution to the problem at hand.

TCallbackContext::LockShared method creates a new TBorrowed object. Its constructor acquires a shared_lock on a mutex stored in the TCallbackContext object.

In a rare situation the LockShared method is called twice in a row from the same thread, but calling lock_shared more than once without releasing the lock leads to undefined behaviour (see https://en.cppreference.com/w/cpp/thread/shared_mutex/lock_shared).

In general, recursive mutexes are frowned upon, but in our case it looks to be the most elegant solution to the problem at hand.
@github-actions
Copy link

github-actions bot commented May 7, 2024

2024-05-07 13:49:44 UTC Pre-commit check for 6bf4b4a has started.
2024-05-07 13:49:47 UTC Build linux-x86_64-release-clang14 is running...
🟢 2024-05-07 13:52:47 UTC Build successful.

@github-actions
Copy link

github-actions bot commented May 7, 2024

2024-05-07 13:49:50 UTC Pre-commit check for 6bf4b4a has started.
2024-05-07 13:49:53 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-05-07 13:53:05 UTC Build successful.
2024-05-07 13:54:54 UTC Tests are running...
🔴 2024-05-07 13:58:36 UTC Test run completed, no test results found for commit 7c28599. Please check build logs.
2024-05-07 13:58:39 UTC Check cancelled

@github-actions
Copy link

github-actions bot commented May 7, 2024

2024-05-07 13:54:05 UTC Pre-commit check for 6bf4b4a has started.
2024-05-07 13:54:06 UTC Build linux-x86_64-release-asan is running...
🟢 2024-05-07 13:57:08 UTC Build successful.
2024-05-07 13:58:34 UTC Check cancelled

@github-actions
Copy link

github-actions bot commented May 7, 2024

2024-05-07 17:03:28 UTC Pre-commit check for f2f777b has started.
2024-05-07 17:03:30 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-05-07 17:06:00 UTC Build successful.
2024-05-07 17:07:38 UTC Tests are running...
🔴 2024-05-07 18:38:17 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
36455 31219 0 4 5224 8

@github-actions
Copy link

github-actions bot commented May 7, 2024

2024-05-07 16:58:41 UTC Pre-commit check for f2f777b has started.
2024-05-07 16:58:43 UTC Build linux-x86_64-release-clang14 is running...
🟢 2024-05-07 17:04:09 UTC Build successful.

@github-actions
Copy link

github-actions bot commented May 7, 2024

2024-05-07 17:10:07 UTC Pre-commit check for f2f777b has started.
2024-05-07 17:10:09 UTC Build linux-x86_64-release-asan is running...
🟢 2024-05-07 17:15:19 UTC Build successful.
2024-05-07 17:16:56 UTC Tests are running...
🔴 2024-05-07 18:53:56 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
9173 9113 0 16 35 9

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.

2 participants