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 - Thread Sanitizer #3708

Closed
popwarfour opened this issue May 17, 2024 · 6 comments
Closed

Data Race - Thread Sanitizer #3708

popwarfour opened this issue May 17, 2024 · 6 comments
Labels
auth Issues related to the Auth category bug Something isn't working core Amplify Core components follow up Requires follow up from maintainers

Comments

@popwarfour
Copy link

Describe the bug

Seeing data race conditions

Steps To Reproduce

1) Enable Thread Sanitization in scheme setting 
2) Setup Auth

Expected behavior

I should not be seeing data race conditions within the library

Amplify Framework Version

2.25.4

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5.9

CLI version

12.10.3

Xcode version

15.3

Relevant log output

WARNING: ThreadSanitizer: data race (pid=4687)
  Write of size 1 at 0x0001473827f9 by thread T29:
    #0 ClientRuntime.HttpResponse.statusCode.setter : ClientRuntime.HttpStatusCode <null> (MyApp:arm64+0x105d7db0c)
    #1 closure #6 (Swift.Result<Swift.UInt32, AwsCommonRuntimeKit.CommonRunTimeError>) -> () in ClientRuntime.CRTClientEngine.(makeHttpRequestStreamOptions in _91B07933650E8EA49FB320ECA4DED537)(request: AwsCommonRuntimeKit.HTTPRequestBase, continuation: Swift.CheckedContinuation<ClientRuntime.HttpResponse, Swift.Error>, http2ManualDataWrites: Swift.Bool) -> AwsCommonRuntimeKit.HTTPRequestOptions <null> (MyApp:arm64+0x105d67298)
    #2 partial apply forwarder for closure #6 (Swift.Result<Swift.UInt32, AwsCommonRuntimeKit.CommonRunTimeError>) -> () in ClientRuntime.CRTClientEngine.(makeHttpRequestStreamOptions in _91B07933650E8EA49FB320ECA4DED537)(request: AwsCommonRuntimeKit.HTTPRequestBase, continuation: Swift.CheckedContinuation<ClientRuntime.HttpResponse, Swift.Error>, http2ManualDataWrites: Swift.Bool) -> AwsCommonRuntimeKit.HTTPRequestOptions <null> (MyApp:arm64+0x105d68600)
    #3 AwsCommonRuntimeKit.(onComplete in _BEB8F7D4C37A431780FEA5A42770A7B4)(stream: Swift.Optional<Swift.UnsafeMutablePointer<__C.aws_http_stream>>, errorCode: Swift.Int32, userData: Swift.Optional<Swift.UnsafeMutableRawPointer>) -> () <null> (MyApp:arm64+0x1056b9d4c)
    #4 @objc AwsCommonRuntimeKit.(onComplete in _BEB8F7D4C37A431780FEA5A42770A7B4)(stream: Swift.Optional<Swift.UnsafeMutablePointer<__C.aws_http_stream>>, errorCode: Swift.Int32, userData: Swift.Optional<Swift.UnsafeMutableRawPointer>) -> () <null> (MyApp:arm64+0x1056b99e4)
    #5 s_stream_complete <null> (MyApp:arm64+0x1058249f0)
    #6 s_decoder_on_done <null> (MyApp:arm64+0x10582d248)
    #7 s_mark_done <null> (MyApp:arm64+0x105833b48)
    #8 s_state_unchunked_body <null> (MyApp:arm64+0x10583468c)
    #9 aws_h1_decode <null> (MyApp:arm64+0x10582eacc)
    #10 s_try_process_next_stream_read_message <null> (MyApp:arm64+0x1058210b4)
    #11 aws_h1_connection_try_process_read_messages <null> (MyApp:arm64+0x10581f9ec)
    #12 s_handler_process_read_message <null> (MyApp:arm64+0x1058277c8)
    #13 aws_channel_handler_process_read_message <null> (MyApp:arm64+0x105798414)
    #14 aws_channel_slot_send_message <null> (MyApp:arm64+0x105797de0)
    #15 s_process_read_message <null> (MyApp:arm64+0x1057b0168)
    #16 aws_channel_handler_process_read_message <null> (MyApp:arm64+0x105798414)
    #17 aws_channel_slot_send_message <null> (MyApp:arm64+0x105797de0)
    #18 s_do_read <null> (MyApp:arm64+0x1057f90d8)
    #19 s_on_readable_notification <null> (MyApp:arm64+0x1057f75dc)
    #20 s_on_socket_io_event <null> (MyApp:arm64+0x1057f043c)
    #21 aws_event_loop_thread <null> (MyApp:arm64+0x105790614)
    #22 thread_fn <null> (MyApp:arm64+0x105753578)

  Previous read of size 1 at 0x0001473827f9 by thread T52:
    #0 ClientRuntime.HttpResponse.statusCode.getter : ClientRuntime.HttpStatusCode <null> (MyApp:arm64+0x105d7daa0)
    #1 (3) suspend resume partial function for ClientRuntime.DeserializeMiddleware.handle<A where A1: ClientRuntime.Handler, A1.Context == ClientRuntime.HttpContext, A1.Input == ClientRuntime.SdkHttpRequest, A1.Output == ClientRuntime.OperationOutput<A>>(context: ClientRuntime.HttpContext, input: ClientRuntime.SdkHttpRequest, next: A1) async throws -> ClientRuntime.OperationOutput<A> <null> (MyApp:arm64+0x105d895c8)
    #2 swift::runJobInEstablishedExecutorContext(swift::Job*) <null> (libswift_Concurrency.dylib:arm64+0x38108)

  Location is heap block of size 42 at 0x0001473827d0 allocated by thread T52:
    #0 malloc <null> (libclang_rt.tsan_iossim_dynamic.dylib:arm64+0x4fa48)
    #1 _malloc_type_malloc_outlined <null> (libsystem_malloc.dylib:arm64+0xf0d0)
    #2 ClientRuntime.CRTClientEngine.(makeHttpRequestStreamOptions in _91B07933650E8EA49FB320ECA4DED537)(request: AwsCommonRuntimeKit.HTTPRequestBase, continuation: Swift.CheckedContinuation<ClientRuntime.HttpResponse, Swift.Error>, http2ManualDataWrites: Swift.Bool) -> AwsCommonRuntimeKit.HTTPRequestOptions <null> (MyApp:arm64+0x105d65928)
    #3 closure #1 (Swift.CheckedContinuation<ClientRuntime.HttpResponse, Swift.Error>) -> () in ClientRuntime.CRTClientEngine.execute(request: ClientRuntime.SdkHttpRequest) async throws -> ClientRuntime.HttpResponse <null> (MyApp:arm64+0x105d61e24)
    #4 partial apply forwarder for closure #1 (Swift.CheckedContinuation<ClientRuntime.HttpResponse, Swift.Error>) -> () in ClientRuntime.CRTClientEngine.execute(request: ClientRuntime.SdkHttpRequest) async throws -> ClientRuntime.HttpResponse <null> (MyApp:arm64+0x105d6250c)
    #5 merged closure #1 (Swift.UnsafeContinuation<A, Swift.Never>) -> () in Swift.withCheckedContinuation<A>(function: Swift.String, _: (Swift.CheckedContinuation<A, Swift.Never>) -> ()) async -> A <null> (libswift_Concurrency.dylib:arm64+0x5740)

  Thread T29 (tid=62930512, running) created by thread T10 at:
    #0 pthread_create <null> (libclang_rt.tsan_iossim_dynamic.dylib:arm64+0x2bee4)
    #1 aws_thread_launch <null> (MyApp:arm64+0x105752d0c)
    #2 s_run <null> (MyApp:arm64+0x10578c474)
    #3 aws_event_loop_run <null> (MyApp:arm64+0x1057b71c0)
    #4 s_event_loop_group_new <null> (MyApp:arm64+0x1057b4f70)
    #5 aws_event_loop_group_new <null> (MyApp:arm64+0x1057b49d4)
    #6 aws_event_loop_group_new_default <null> (MyApp:arm64+0x1057b51c8)
    #7 closure #1 (Swift.UnsafePointer<__C.aws_shutdown_callback_options>) -> Swift.Optional<Swift.UnsafeMutablePointer<__C.aws_event_loop_group>> in closure #1 () -> Swift.Optional<Swift.UnsafeMutablePointer<__C.aws_event_loop_group>> in AwsCommonRuntimeKit.EventLoopGroup.init(threadCount: Swift.UInt16, shutdownCallback: Swift.Optional<() -> ()>) throws -> AwsCommonRuntimeKit.EventLoopGroup <null> (MyApp:arm64+0x1056bcbec)
    #8 partial apply forwarder for closure #1 (Swift.UnsafePointer<__C.aws_shutdown_callback_options>) -> Swift.Optional<Swift.UnsafeMutablePointer<__C.aws_event_loop_group>> in closure #1 () -> Swift.Optional<Swift.UnsafeMutablePointer<__C.aws_event_loop_group>> in AwsCommonRuntimeKit.EventLoopGroup.init(threadCount: Swift.UInt16, shutdownCallback: Swift.Optional<() -> ()>) throws -> AwsCommonRuntimeKit.EventLoopGroup <null> (MyApp:arm64+0x1056bcd9c)
    #9 Swift.withUnsafePointer<A, B>(to: A, _: (Swift.UnsafePointer<A>) throws -> B) throws -> B <null> (libswiftCore.dylib:arm64+0x116f24)
    #10 AwsCommonRuntimeKit.EventLoopGroup.init(threadCount: Swift.UInt16, shutdownCallback: Swift.Optional<() -> ()>) throws -> AwsCommonRuntimeKit.EventLoopGroup <null> (MyApp:arm64+0x1056bc780)
    #11 AwsCommonRuntimeKit.EventLoopGroup.__allocating_init(threadCount: Swift.UInt16, shutdownCallback: Swift.Optional<() -> ()>) throws -> AwsCommonRuntimeKit.EventLoopGroup <null> (MyApp:arm64+0x1056bc5c4)
    #12 ClientRuntime.SDKDefaultIO.() -> ClientRuntime.SDKDefaultIO(in _FE859A5DC63535809337AB8A60C1C338).init() -> ClientRuntime.SDKDefaultIO <null> (MyApp:arm64+0x105d6d564)
    #13 ClientRuntime.SDKDefaultIO.__allocating_init() -> ClientRuntime.SDKDefaultIO <null> (MyApp:arm64+0x105d6d310)
    #14 one-time initialization function for shared <null> (MyApp:arm64+0x105d6d288)
    #15 dispatch_once <null> (libclang_rt.tsan_iossim_dynamic.dylib:arm64+0x78d30)
    #16 dispatch_once_f <null> (libclang_rt.tsan_iossim_dynamic.dylib:arm64+0x78dcc)
    #17 ClientRuntime.SDKDefaultIO.shared.unsafeMutableAddressor : ClientRuntime.SDKDefaultIO <null> (MyApp:arm64+0x105d6d3bc)
    #18 AWSClientRuntime.DefaultChainCredentialsProvider.init(fileBasedConfig: AwsCommonRuntimeKit.FileBasedConfiguration) throws -> AWSClientRuntime.DefaultChainCredentialsProvider <null> (MyApp:arm64+0x105599738)
    #19 AWSClientRuntime.AWSClientConfiguration.__allocating_init(region: Swift.String, credentialsProvider: Swift.Optional<AWSClientRuntime.CredentialsProviding>, endpoint: Swift.Optional<Swift.String>, serviceSpecific: Swift.Optional<A>, signingRegion: Swift.Optional<Swift.String>, useDualStack: Swift.Optional<Swift.Bool>, useFIPS: Swift.Optional<Swift.Bool>, retryMode: Swift.Optional<AWSClientRuntime.AWSRetryMode>, maxAttempts: Swift.Optional<Swift.Int>, appID: Swift.Optional<Swift.String>, connectTimeoutMs: Swift.Optional<Swift.UInt32>) throws -> AWSClientRuntime.AWSClientConfiguration<A> <null> (MyApp:arm64+0x10559106c)
    #20 AWSCognitoAuthPlugin.AWSCognitoAuthPlugin.(makeUserPool in _8AB0DFBFCB62BEA0C3EE23AA1F6DBA04)() throws -> AWSCognitoAuthPlugin.CognitoUserPoolBehavior <null> (MyApp:arm64+0x104aee818)
    #21 implicit closure #4 () throws -> AWSCognitoAuthPlugin.CognitoUserPoolBehavior in implicit closure #3 (AWSCognitoAuthPlugin.AWSCognitoAuthPlugin) -> () throws -> AWSCognitoAuthPlugin.CognitoUserPoolBehavior in AWSCognitoAuthPlugin.AWSCognitoAuthPlugin.(authenticationEnvironment in _8AB0DFBFCB62BEA0C3EE23AA1F6DBA04)(userPoolConfigData: AWSCognitoAuthPlugin.UserPoolConfigurationData) -> AWSCognitoAuthPlugin.AuthenticationEnvironment <null> (MyApp:arm64+0x104af1814)
    #22 partial apply forwarder for implicit closure #4 () throws -> AWSCognitoAuthPlugin.CognitoUserPoolBehavior in implicit closure #3 (AWSCognitoAuthPlugin.AWSCognitoAuthPlugin) -> () throws -> AWSCognitoAuthPlugin.CognitoUserPoolBehavior in AWSCognitoAuthPlugin.AWSCognitoAuthPlugin.(authenticationEnvironment in _8AB0DFBFCB62BEA0C3EE23AA1F6DBA04)(userPoolConfigData: AWSCognitoAuthPlugin.UserPoolConfigurationData) -> AWSCognitoAuthPlugin.AuthenticationEnvironment <null> (MyApp:arm64+0x104af79a0)
    #23 (1) suspend resume partial function for AWSCognitoAuthPlugin.AWSAuthFetchUserAttributeTask.getUserAttributes(with: Swift.String) async throws -> Swift.Array<Amplify.AuthUserAttribute> <null> (MyApp:arm64+0x10523de3c)
    #24 swift::runJobInEstablishedExecutorContext(swift::Job*) <null> (libswift_Concurrency.dylib:arm64+0x38108)

  Thread T52 (tid=62931679, running) is a GCD worker thread

SUMMARY: ThreadSanitizer: data race (/Users/andersmelen/Library/Developer/CoreSimulator/Devices/26B50286-E86D-4C5E-BE5C-1B37155233DA/data/Containers/Bundle/Application/765655DB-80F2-4044-AB8F-EDA8230A137E/MyApp.app/MyApp:arm64+0x105d7db0c) in ClientRuntime.HttpResponse.statusCode.setter : ClientRuntime.HttpStatusCode+0x44
==================
ThreadSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report.

Is this a regression?

No

Regression additional context

No response

Platforms

No response

OS Version

17.4

Device

iPhone 15 Pro

Specific to simulators

No response

Additional context

No response

@thisisabhash
Copy link
Member

Thank you posting this - our team will investigate and post updates to this ticket.

@thisisabhash thisisabhash added core Amplify Core components auth Issues related to the Auth category bug Something isn't working labels May 17, 2024
@5d
Copy link
Member

5d commented May 21, 2024

A pull request (smithy-lang/smithy-swift#656) addressing this issue has already been submitted for the smithy-swift repository. We will track it progress.

@sichanyoo
Copy link

This particular thread-safety warning has been fixed with this PR: smithy-lang/smithy-swift#656.
This change will go out with the next bi-weekly release of aws-sdk-swift, v0.45.0.
This change will be effective for upstream customers of Amplify once Amplify bumps their dependency on aws-sdk-swift.

@5d
Copy link
Member

5d commented May 30, 2024

We will try to upgrade to the latest version once it's released.

@lawmicha lawmicha added the follow up Requires follow up from maintainers label Jun 4, 2024
@harsh62
Copy link
Member

harsh62 commented Jul 16, 2024

The update to the SDK is being tracked in #3629

@harsh62 harsh62 closed this as completed Jul 16, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please 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
auth Issues related to the Auth category bug Something isn't working core Amplify Core components follow up Requires follow up from maintainers
Projects
None yet
Development

No branches or pull requests

6 participants