-
Notifications
You must be signed in to change notification settings - Fork 158
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
logging: fix race condition in changing the logger #891
Conversation
This condition was found via clang TSAN analyzer. aws_logger_set/get operate on a global variable, but the operation on the shared global variable is not thread-safe. Use a mutex to avoid the race condition.
result = s_root_logger_ptr; | ||
aws_mutex_unlock(&s_root_logger_lock); | ||
|
||
return result; |
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.
This returns a pointer to the aws_logger(). The pointer can still access the underlying data in such a way that introduces a data race.
struct aws_logger * logger = aws_logger_get();
logger->foo = xx;
Since this can still race, AWS needs to provide a better solution here, whereby the API is changed to return a copy.
Hi Gerrit, Thank you for the contribution. This API is not thread safe and must only be called once. Please feel free to reopen the PR if there is anything else. aws-c-common/include/aws/common/logging.h Line 222 in 4b4675c
|
This is a very old PR. The condition occurred when To avoid that problem, we have been using a dedicated initializer thread, which takes care of calling Should the problem re-occur, I will create an issue. |
…be called from the same thread Running InitAPI() and ShutdownAPI() from different threads can cause subtle problems, see e.g. - aws/s2n-tls#3525 - awslabs/aws-c-common#891 Add a note for users to use the same thread.
…be called from the same thread Running InitAPI() and ShutdownAPI() from different threads can cause subtle problems, see e.g. - aws/s2n-tls#3525 - awslabs/aws-c-common#891 Add a note for users to use the same thread.
…be called from the same thread Running InitAPI() and ShutdownAPI() from different threads can cause subtle problems, see e.g. - aws/s2n-tls#3525 - awslabs/aws-c-common#891 Add a note for users to use the same thread.
This race condition was found via clang TSAN analyzer.
aws_logger_set/get
operate on a global variable, but the operation on the shared global variable is not thread-safe.Use a
mutex
to avoid the race condition.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.