-
Notifications
You must be signed in to change notification settings - Fork 504
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
Fix data race when joining the task runner #1493
Fix data race when joining the task runner #1493
Conversation
Currently, server->Join will join the task runner before the cron thread, so it may have the data race since the cron thread may acess the task runner as well. We can avoid this by removing the task runner join which will do in the task runner destructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Sounds legitimate to me.
@torwig Thanks for your quick review. |
Could you specify the location of another Join call of the task runner? |
Sure, the TaskRunner destructor will join as well: https://github.com/apache/incubator-kvrocks/blob/unstable/src/common/task_runner.h#L49 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Although a dtor with a long time waiting may cause some misunderstanding.
Yes, I think we can remove the Cancel and Join in dtor since the Server::Stop will cancel the task runner first. Can take a look again. @PragmaTwice @torwig |
@git-hulk Yes, |
oooh, my bad. I didn't see that, updated. |
@git-hulk My idea was to change the loop to the following:
What do you think about that? @PragmaTwice What is your opinion on that? |
Yes, it's good to only log an error when failing to join since other places like the worker thread only print an error. |
Seems good to me. |
Thanks all, merging... |
This may close #1448
Currently, server->Join will join the task runner before the cron thread, so it may have the data race since the cron thread may access the task runner as well. We can avoid this by removing the task runner join which will do in the task runner destructor.