Skip to content

ydb_topic: do not call lock_shared recursively #4366

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

Merged

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.
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.

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

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

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

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.

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

qyryq added a commit to qyryq/ydb that referenced this pull request May 7, 2024
qyryq added a commit to qyryq/ydb that referenced this pull request May 7, 2024
@qyryq qyryq merged commit 1c9ad9d into ydb-platform:main May 8, 2024
3 of 5 checks passed
MrLolthe1st pushed a commit to MrLolthe1st/ydb that referenced this pull request May 28, 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.

2 participants