braze-inc / braze-swift-sdk

Braze SDK for the Apple ecosystem, including: iOS, macOS, iPadOS, visionOS, tvOS
https://www.braze.com
Other
50 stars 19 forks source link

[Bug]: App Hanging when starting Braze SDK with print function setup #67

Closed MaryBurshtyn closed 11 months ago

MaryBurshtyn commented 1 year ago

Platform

iOS

Platform Version

macOS 12 / macOS 13

Braze SDK Version

6.3.0

Xcode Version

14.2/14.3

Computer Processor

Intel

Repro Rate

100%

Steps To Reproduce

Setup Braze:

let brazeConfig = Braze.Configuration(apiKey: apiKey, endpoint: endpoint)
brazeConfig.logger.print = self.logBraze
brazeConfig.logger.level = .info
self.brazeInstance = Braze(configuration: brazeConfig)
brazeInstance?.enabled = true

In case if logBraze function save logs locally on the device it works perfectly fine. But if logBraze function sends logs to Embrace app freezes. Freezing happens only if Embrace logging performed from print function in other cases Embrace log work fine too.

Expected Behavior

App should not freeze while Embrace logging from set print function.

Actual Incorrect Behavior

App freezes on Braze init function.

Verbose Logs

Thread 1 Queue : com.apple.main-thread (serial)
#0  0x00000001b7ea7540 in semaphore_wait_trap ()
#8  0x0000000102e074c8 in Braze.__allocating_init(configuration:) [inlined] ()
#9  0x0000000102e074c4 in BrazeService.startBraze()
#10 0x0000000102e4cb8c in BrazeService.setUser(uuid:userData:) [inlined]
#11 0x0000000102e4cb78 in protocol witness for BrazeServiceProtocol.setUser(uuid:userData:) in conformance BrazeService [inlined]

Additional Information

Also happens on M1 processor.

jerielng commented 1 year ago

Hey @MaryBurshtyn, thanks for sharing this information. If possible, would you mind sharing the code for your logBraze function? If I understand this correctly, it seems to be freezing inside that function when you call the Embrace function.

Where are you observing the freeze to occur in your debugging? If you set some breakpoints, does the runtime stop at the Embrace line?

lowip commented 1 year ago

Hi @MaryBurshtyn,

Could you try wrapping the body of your logBraze method in a DispatchQueue.main.async { ... } expression?

Our SDK initialization is synchronous and blocks the calling thread until fully initialized. It seems that Embrace itself may have some internal logic leading to a deadlock when logs are emitted by the SDK during its initialization.

Wrapping your custom log code in a DispatchQueue.main.async { ... } expression will ensure that the SDK is fully initialized before Embrace tries to process the logs.

hokstuff commented 11 months ago

Since this issue is several months old and we have described suggestions for possible workarounds, I will close this ticket as stale. If you continue to run into issues about this topic, feel free to open a ticket with support@braze.com.

Thanks!