-
Notifications
You must be signed in to change notification settings - Fork 18
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
Data race on aws_logger
global var
#281
Comments
CRT logger is not thread safe and must be only called once. See: https://github.com/awslabs/aws-c-common/blob/main/include/aws/common/logging.h#L239. I can update the documentation for the Swift function. |
Ensuring proper use and initialization of aws-crt-swift's underlying C dependencies cannot be a responsibility of aws-crt-swift consumers. When aws-crt-swift is used in a multithreaded environment, it should ensure that it dependencies' API requirements are met. |
I agree with the statement, and I can think of a few options, such as putting a lock around it or making the re-initialization a no-op to fix it on the CRT side. I will look into making this a better experience, but it won't change the fact that the CRT logger is global and not client-level, and should not be exposed as such. The use case of having a different logger for different clients won't work with CRT's current logger. If client A initializes the logger with TRACE level and client B initializes it with ERROR level, it will override client A's logger with client B's, since there is only one global logger. |
This is fixed in https://github.com/awslabs/aws-crt-swift/releases/tag/v0.35.0. |
|
Describe the bug
When multiple SDK service clients are created simultaneously on different threads, a data race can be observed on the
aws_logger
global variable, where one thread is setting the var & another attempts to read it before the set is complete. Data race can be observed in the Xcode Thread Sanitizer.Expected Behavior
Exclusive access to the logger should be enforced while it is set.
Current Behavior
Simultaneous get & set access happens, as seen in the screenshot above.
Reproduction Steps
Turn on Xcode thread sanitizer.
Create multiple file-based configurations on different threads.
Observe race condition shown above.
Possible Solution
No response
Additional Information/Context
No response
aws-crt-swift version used
0.33.0
Compiler and Version used
Xcode 15.4
Operating System and version
macOS 14.6.1
The text was updated successfully, but these errors were encountered: