Skip to content
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

Closed
jbelkins opened this issue Sep 5, 2024 · 5 comments
Closed

Data race on aws_logger global var #281

jbelkins opened this issue Sep 5, 2024 · 5 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@jbelkins
Copy link
Contributor

jbelkins commented Sep 5, 2024

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

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

@jbelkins jbelkins added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 5, 2024
@waahm7
Copy link
Contributor

waahm7 commented Sep 5, 2024

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.

@jbelkins
Copy link
Contributor Author

jbelkins commented Sep 5, 2024

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.

@waahm7
Copy link
Contributor

waahm7 commented Sep 5, 2024

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.

@waahm7
Copy link
Contributor

waahm7 commented Sep 12, 2024

@waahm7 waahm7 closed this as completed Sep 12, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants