-
Notifications
You must be signed in to change notification settings - Fork 222
Description
Describe the bug
While configuring Amplify with an AWSCloudWatchLoggingPluginConfiguration and an AWSCognitoAuthPlugin configuration the library has a race condition that crashes the application 50% of the time with an error of Thread 20: Fatal error: Authentication category is not configured. Call Amplify.configure() before using any methods on the category.
The problem is that these two configurations are added to Amplify and this crash occurs when calling Amplify.configure().
Order of Methods that causes crash to occur:
try configure(CategoryType.logging.category, using: resolvedConfiguration)
try configurable.configure(using: configuration)
try configure(using: categoryConfiguration(from: amplifyConfiguration))
try Amplify.configure(plugins: Array(plugins.values), using: configuration)
try plugin.configure(using: pluginConfiguration)
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
self.loggingClient.takeUserIdentifierFromCurrentUser()
}
func takeUserIdentifierFromCurrentUser() {
Task {
do {
let user = try await authentication.getCurrentUser()
self.userIdentifier = user.userId
} catch {
self.userIdentifier = nil
}
self.updateSessionControllers()
}
}
public func getCurrentUser() async throws -> AuthUser {
try await plugin.getCurrentUser()
}
return Fatal.preconditionFailure(
"""
\(categoryType.displayName) category is not configured. Call Amplify.configure() before using \
any methods on the category.
"""
)
Steps To Reproduce
Steps to reproduce the behavior:
1. Add AWSCloudWatchLoggingPluginConfiguration and AWSCognitoAuthPlugin to Amplify:
private func addAuthenticationPlugin() throws {
let authPlugin = AWSCognitoAuthPlugin(networkPreferences: Self.networkPreferences)
do {
try Amplify.add(plugin: authPlugin)
} catch {
throw error
}
}
private func addCloudWatchLoggingPlugin() throws {
do {
let logLevels: [String: LogLevel] = ["AWSAuthFetchSessionTask": .error]
let loggingConstraints = LoggingConstraints(defaultLogLevel: .debug, categoryLogLevel: logLevels)
let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "your log group",
region: "us-east-1",
localStoreMaxSizeInMB: 1,
flushIntervalInSeconds: 10,
loggingConstraints: loggingConstraints)
let plugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration)
try Amplify.add(plugin: plugin)
} catch {
throw error
}
}
2. load a amplifyconfiguration.json and call configure:
private func loadAmplifyConfiguration() throws {
do {
let amplifyConfig = try getLocalAmplifyConfigurationFile()
try Amplify.configure(amplifyConfig)
} catch {
throw error
}
}
3. On iPhone 15 Pro Max and newer seems to crash way more often.
Expected behavior
The AWSCloudWatchLoggingPluginConfiguration shouldn't be asking for Authentication details during it's configuration...the library says you can only call configure() once, so configuring Auth and then Logging isn't possible.
Amplify Framework Version
2.41.1
Amplify Categories
Analytics, API, Auth
Dependency manager
Swift PM
Swift version
5.8.0
CLI version
I am not sure
Xcode version
16.0
Relevant log output
No response
Is this a regression?
Yes
Regression additional context
No response
Platforms
iOS
OS Version
IOS 18
Device
iPhone 15 Pro Max
Specific to simulators
no
Additional context
No response