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

File upload failing in background #3876

Open
amruth-movano opened this issue Sep 19, 2024 · 4 comments
Open

File upload failing in background #3876

amruth-movano opened this issue Sep 19, 2024 · 4 comments
Labels
bug Something isn't working storage Issues related to the Storage category

Comments

@amruth-movano
Copy link

Describe the bug

Hi Team,
We have application which connection with BLE device and for each min it syncs data and as soon as sync completes it uploads the file to s3 for that particular sync.

So we are observing failure in files when app is in background overnight which is causing UI to hang when user come to foreground in the morning.

Please see logs attached

Steps To Reproduce

Upload log file for each min in background overnight

Expected behavior

All File should get upload

Amplify Framework Version

2.39.0

Amplify Categories

Storage

Dependency manager

Swift PM

Swift version

5.9.2

CLI version

12.11.1

Xcode version

15.2

Relevant log output

2024/09/19 15:07:04:798  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log, error: StorageError: The HTTP response status code is [503].
Recovery suggestion: Server error.
For more information on HTTP status codes, take a look at
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
2024/09/19 15:07:04:801  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:05:135  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log, error: StorageError: The HTTP response status code is [503].
Recovery suggestion: Server error.
For more information on HTTP status codes, take a look at
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
2024/09/19 15:07:05:143  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:05:146  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:05:175  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:05:189  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:05:295  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log, error: StorageError: The HTTP response status code is [400].
Recovery suggestion: Client error.
For more information on HTTP status codes, take a look at
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
2024/09/19 15:07:05:295  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log, error: StorageError: The HTTP response status code is [400].
Recovery suggestion: Client error.
For more information on HTTP status codes, take a look at
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
2024/09/19 15:07:06:053  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:06:057  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:06:059  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:06:084  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log, error: StorageError: The HTTP response status code is [400].
Recovery suggestion: Client error.
For more information on HTTP status codes, take a look at
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
2024/09/19 15:07:06:091  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:07:06:128  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <F76769CF-2E72-432F-A16F-7992885EE371>.<1955>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <F76769CF-2E72-432F-A16F-7992885EE371>.<1955>}
2024/09/19 15:07:06:131  Get user profile from keychain
2024/09/19 15:07:06:156  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <CA69D620-A35A-44CE-B738-9EA00788204F>.<1956>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <CA69D620-A35A-44CE-B738-9EA00788204F>.<1956>}
2024/09/19 15:07:06:169  Get user profile from keychain
2024/09/19 15:07:06:169  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <CB5E12AF-9E3A-4CA9-9B26-FC96A6C1BA23>.<1957>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <CB5E12AF-9E3A-4CA9-9B26-FC96A6C1BA23>.<1957>}
2024/09/19 15:07:06:172  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <9CF73380-8AA8-440E-80B9-E1946ED0B340>.<1958>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <9CF73380-8AA8-440E-80B9-E1946ED0B340>.<1958>}
2024/09/19 15:07:06:180  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <6E09EB75-C6F1-4043-B3A4-5F01E08F5932>.<1959>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <6E09EB75-C6F1-4043-B3A4-5F01E08F5932>.<1959>}
2024/09/19 15:07:06:226  Successfully uploaded log file: com.movano.ios.staging 2024-09-19--14-08-39-830.log
2024/09/19 15:10:30:308  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <062DC85B-BDA8-44EE-A920-102A4B4A443B>.<1960>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <062DC85B-BDA8-44EE-A920-102A4B4A443B>.<1960>}
2024/09/19 15:10:30:308  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <EB392810-F7BE-4F54-8418-64022BDF5A2B>.<1961>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <EB392810-F7BE-4F54-8418-64022BDF5A2B>.<1961>}
2024/09/19 15:10:30:308  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <22004E69-441C-461A-99E4-BFD0CD9DE072>.<1963>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <22004E69-441C-461A-99E4-BFD0CD9DE072>.<1963>}
2024/09/19 15:10:30:308  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <43651E90-6224-4728-A00F-426ABF90164B>.<1962>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <43651E90-6224-4728-A00F-426ABF90164B>.<1962>}
2024/09/19 15:10:30:308  Failed to upload or delete log file: com.movano.ios.staging 2024-09-19--06-14-40-693.log, error: StorageError: Unexpected error occurred with message: Response is not an HTTP response
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/runner/Library/Developer/Xcode/DerivedData/MovanoRing-fxwtpneshqrfliflkjfdocpebocf/SourcePackages/checkouts/amplify-ios/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion
line: 104
Caused by:
Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
    "BackgroundUploadTask <2F8563DC-841C-4EE2-AA51-61E89464A98B>.<1964>"
), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask <2F8563DC-841C-4EE2-AA51-61E89464A98B>.<1964>}

Is this a regression?

Yes

Regression additional context

No response

Platforms

iOS

OS Version

iOS 17.5.1

Device

iPhone 14 Pro

Specific to simulators

No response

Additional context

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Sep 19, 2024
@phantumcode
Copy link
Member

@amruth-movano Thanks for submitting the issue. To help us reproduce the issue and investigate further, can you provide a sample app or sample code that demonstrates how you're executing the upload?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 19, 2024
@phantumcode phantumcode added bug Something isn't working pending-maintainer-response Issue is pending response from an Amplify team member storage Issues related to the Storage category pending-community-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Sep 19, 2024
@amruth-movano
Copy link
Author

amruth-movano commented Sep 19, 2024

@phantumcode

We have create one wrapper class -

import Amplify
import AWSS3StoragePlugin
import Foundation
import Resolver

protocol RemoteFileStoragable {
    func store(localFile: URL, remoteName: String) async throws -> String
}

final class AmplifyFileStorage: RemoteFileStoragable {

    private let storage: StorageCategoryBehavior
    @Injected private var eventTracker: TelemetryTracker

    init(_ storage: StorageCategoryBehavior = Amplify.Storage) {
        self.storage = storage
    }

    func store(localFile fileUrl: URL, remoteName: String) async throws -> String {
        let uploadTask = storage.uploadFile(
            key: remoteName,
            local: fileUrl,
            options: nil
        )

        for await progress in await uploadTask.progress {
            let percentage = Int(round(progress.fractionCompleted * 100))
            eventTracker.track(event: .logOnly(message: "[AmplifyFileStorage] - Upload Progress (\(fileUrl.lastPathComponent)): \(percentage)%"))
        }
        let result = try await uploadTask.value
        return result
    }
}

And in another class we directly use the function to upload -

// Declaration - 
@Injected private var remoteFileStorage: RemoteFileStoragable


// Use
let result = try await remoteFileStorage.store(localFile: filePath, remoteName: "\(parentFolderName)/\(userId)/\(filename).zip")

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Sep 19, 2024
@phantumcode
Copy link
Member

phantumcode commented Sep 19, 2024

@amruth-movano Thanks for providing the sample code, we'll take a look.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 19, 2024
@phantumcode
Copy link
Member

@amruth-movano Can you provide details on how your app has been configured for different background modes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working storage Issues related to the Storage category
Projects
None yet
Development

No branches or pull requests

2 participants