aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 884 forks source link

Uploading files with a content size >~ 2.1 GB do not restart properly #5468

Open kaloramik opened 22 hours ago

kaloramik commented 22 hours ago

Describe the bug

I am utilizing the behavior in the Swift TransferUtility documentation here https://docs.amplify.aws/gen1/swift/sdk/storage/transfer-utility/#managing-transfers-when-an-app-restarts

I have tested this with a 1.75 GB file and a 2.3 GB file. It seems to work correctly for the 1.75 GB file, but not for the 2.3 GB file.

In the 2.3 GB case, the contentLength gets changed to something negative. One possible hypothesis could be that 2.3 GB is larger than the size of a 32 bit signed int?

To Reproduce Base case

  1. Try uploading a file of size < 2.1 GB
  2. use Fast App Termination and put app in background to simulate the app getting terminated by the system
  3. re-open app
  4. after a few minutes, the app correctly associates the upload and finishes

Steps to reproduce the behavior:

  1. Try uploading a file of size > 2.1 GB
  2. use Fast App Termination and put app in background to simulate the app getting terminated by the system
  3. re-open app
  4. after a few minutes, you can see onProgress callbacks, but the progress is always 0 and task.contentLength is negative
  5. Eventually, the upload will fail with the following error
com.amazonaws.AWSS3TransferUtilityErrorDomain - 2: Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=2 "(null)" UserInfo={Message=Expected to send [-1962180493], but sent [2332786803] and there are no remaining parts. Failing transfer }

Observed Behavior see above Expected Behavior

A clear and concise description of what you expected to happen.

Stack Trace Please provide a stack trace if applicable e.g. a crash is occurring.

I am logging to Datadog here

  private func handleProgress(task: MultiPartUploadTask, progress: Progress) {
    NavigateDD.logger?.info("in handle progress \(task.file) \(task.location) \(task.file) \(task.status) \(task.error) \(task.description) \(task.key) \(task.contentLength) \(task.completedPartsSet.count)")
    let progressParams = ["progress": progress.fractionCompleted]
    let event = self.createEvent(task: task, customParams: progressParams)
    self.sendEvent(withName: PROGRESS_EVENT, body: event)
  }

you can see here where after the app restarts, the contentLength changes Screenshot 2024-12-01 at 1 09 38 PM

Note that the original content length was 2332786803. the new content length is -1962180493 This is the value of the former as a signed int

>>> def get_signed_value(unsigned_int):
...     signed_value = large_value & 0xFFFFFFFF
...     if signed_value >= 2**31:
...             signed_value -= 2**32
...     return signed_value
...
>>> get_signed_value(2332786803)
-1962180493

Code Snippet I have generally followed the same instructions in the AutoResume sample app

Unique Configuration If you are reporting an issue with a unique configuration or where configuration can make a difference in code execution (i.e. Cognito) please provide your configuration. Please make sure to obfuscate sensitive information from the configuration before posting.

Areas of the SDK you are using (AWSMobileClient, Cognito, Pinpoint, IoT, etc)?

Screenshots If applicable, add screenshots to help explain your problem.

Environment(please complete the following information):

Device Information (please complete the following information):

Additional context Add any other context about the problem here like your specific use case.

Relevant Console Output In some cases, it might be helpful to add any logs from your console that better help you tell the story of this issue. You can easily enable logging in your app by putting the following code in your app delegate.

AWSDDLog.sharedInstance.logLevel = .debug
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)

Logs

Please logs in the code block below. (See: Logs Guidance)

Log Messages ``` INSERT LOG MESSAGES HERE ```
tylerjroach commented 6 hours ago

Thank you for your report. I will go ahead and label this as a bug while we attempt to replicate the issue.

harsh62 commented 2 hours ago

@kaloramik Is using Amplify a possibility for you? Amplify uses the latest feature sets and has lot of improvements compared to AWS SDK.