aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
455 stars 196 forks source link

Upload failure with error Amplify.StorageError error 7 #3726

Closed Ankish closed 5 months ago

Ankish commented 5 months ago

Describe the bug

Upload fails with unexpected message from AWS to log bug. Amplify.StorageError error 7

Steps To Reproduce

Happens randomly

Expected behavior

Should not throw unexpected error

Amplify Framework Version

2.34.1

Amplify Categories

Storage

Dependency manager

Swift PM

Swift version

5.10

CLI version

aws-amplify-cli/2.0

Xcode version

15.3

Relevant log output

<details>
<summary>Log Messages</summary>

No logs present



### Is this a regression?

No

### Regression additional context

_No response_

### Platforms

iOS

### OS Version

iOS 16 & iOS 17

### Device

iPhone 13

### Specific to simulators

_No response_

### Additional context

    "error": "The operation couldn’t be completed. (Amplify.StorageError error 7.)",
    "error_debug": "StorageError: Unexpected error occurred with message: An unknown error occurred\nRecovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-io",
    "error_recovery": "This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the",
5d commented 5 months ago

Thanks for submitting the issue. We will investigate further and provide updates here.

5d commented 5 months ago

We need more information to proceed with the investigation. Please reopen the ticket and include additional details, such as verbose logs, crash logs, and steps to reproduce the issue.

github-actions[bot] commented 5 months ago

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.

Ankish commented 5 months ago

@5d : Can you tell me in your SDK when does error 7 is reported, it will help me replicate it. We are seeing lot of random failures, I will switch on the log and try to provide you soon. Also error clearly indicates this should not be happening.

5d commented 5 months ago

The error code 7 corresponds to StorageError.unknown. Several conditions can lead to StorageError.unknown error. To proceed with further investigation, we need at least the stack trace, logs, or steps to reproduce the issue.

Ankish commented 5 months ago

Is there a way to dump AWS logs into local file , we dont have cloudwatch, Testers are able to reproduce it and will be easy if thats possible.

5d commented 5 months ago

You can enable verbose logging to the console by doing this before calling Amplify.configure:

Amplify.Logging.logLevel = .verbose
Ankish commented 5 months ago

@5d : Yes we can switch on the logs and watch console but we cant dump to a local file. Is there a way to do that ? We need to uploads tons of videos to replicate that. What would be the best way to pass the. logs to you ?

5d commented 5 months ago

Sorry, the default logging plugin utilizes os_log internally and it does not have an option to redirect the output stream to a file.

Ankish commented 5 months ago

@5d : Isnt there a way to make All AWS logging to be logged in AWS Cloud watch with this configuration:


 let loggingConstraints = LoggingConstraints(defaultLogLevel: .verbose)
        let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "/ios-development-analytics", region: "us-west-2", localStoreMaxSizeInMB: 1, flushIntervalInSeconds: 60, loggingConstraints: loggingConstraints)
        let loggingPlugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration)
        loggingPlugin.enable()
        try Amplify.add(plugin: loggingPlugin)```
5d commented 5 months ago

Yes. To access the logs remotely, you can utilize our Cloudwatch logging plugin. Please refer to our Cloudwatch logging setup documentation, which provides detailed instructions. In addition to the code snippet mentioned, there are other configurations required. For instance, you will need to attach the appropriate Cloudwatch permissions to your IAM roles.

Ankish commented 5 months ago

@5d

Failure log:

2024-06-06 19:51:20.566760+0530 AppX[501:15238] [AuthenticationAWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signedIn" =         {
            deviceMetadata = "[\"noData\": \"noData\"]";
            signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.userSRP)";
            signedInDate = "2024-06-06 14:10:45 +0000";
            tokens = "[\"idToken\": \"ey*****NQ\", \"accessToken\": \"ey*****yQ\", \"refreshToken\": \"ey*****_w\", \"expiry\": 2024-06-07 14:10:45 +0000]";
            userId = "f3********************************f1";
            userName = "f3********************************f1";
        };
        "AuthorizationState.refreshingSession" =         {
            existing = userPoolAndIdentityPool;
            refreshState =             {
                "RefreshSessionState.refreshingAWSCredentialsWithUserPoolTokens" =                 {
                };
            };
        };
    };
}
2024-06-06T19:51:20+0530 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity, 
User-Agent: aws-sdk-swift/1.0 ua/2.0 api/cognito_identity#1.0 os/ios#16.6.1 lang/swift#5.10 cfg/retry-mode#legacy, 
Content-Type: application/x-amz-json-1.1, 
Host: cognito-identity.us-west-2.amazonaws.com, 
Content-Length: 1049 
 nil
2024-06-06 19:51:20.860652+0530 AppX[501:15429] [Storage] Multipart Upload Failure: StorageError: Unexpected error occurred with message: An unknown error occurred
Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at:
file: /Users/User1/Library/Developer/Xcode/DerivedData/AppX-fkeyylrucnmyzkeqidfpwskedqfx/SourcePackages/checkouts/amplify-swift/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
UnknownAWSHTTPServiceError(typeName: Optional("RequestTimeTooSkewed"), message: Optional("The difference between the request time and the current time is too large."), requestID: Optional("S70MY5M2RQ6HYFED"), requestID2: Optional("lJ+M4YlcnBeI7dxeA8CYnIcSEGhCOhXJ+aT81yjPrIMAX1OQJE3pWBUr7AuYXVRq583GPxSqO+zQroXJ3mO+cg=="), httpResponse: 
Status Code: http_status_403 
 Server: AmazonS3, 
Content-Type: application/xml, 
x-amz-id-2: lJ+M4YlcnBeI7dxeA8CYnIcSEGhCOhXJ+aT81yjPrIMAX1OQJE3pWBUr7AuYXVRq583GPxSqO+zQroXJ3mO+cg==, 
Transfer-Encoding: Identity, 
Date: Thu, 06 Jun 2024 08:01:18 GMT, 
x-amz-request-id: S70MY5M2RQ6HYFED)

PFA log:

LogsAWS.txt

Device was in airplane mode, then internet logged in, tried uploading , it fails with this error:

5d commented 5 months ago

Hi @Ankish , Based on the error in the log, it appears that your device's time is not synchronized with the world clock. Does your testing device have automatic time correction enabled? Please refer to the Apple documentation to set the time to automatic and verify if the issue persists.