Skip to content

Issue with TUSKit uploads pausing in the background and high memory usage when pausing and resuming uploads. #204

@muthuvelWorkflowlabs

Description

@muthuvelWorkflowlabs

I'm encountering an issue with the TusKit iOS library where uploads pause when the app goes into the background and automatically resume when it returns to the foreground. To address this, I tried setting the chunk size to 0, which allowed the uploads to continue in the background. However, this approach leads to the app being terminated by the system due to excessive memory usage when pausing and resuming uploads of files larger than 2GB
Note: This crash does not occur if the upload runs continuously without being paused and resumed.

Steps to Reproduce:
1 Implement resumable uploads using TusKit in an iOS app.
2 Set the chunk size to 0 in the TUSClient initialization.
3 Attempt to upload a file larger than 2GB.
4 Observe that the app crashes due to high memory usage when uploads are paused and resumed.

Expected Behavior:
• The uploads should continue in the background without causing a memory-related crash.

Actual Behavior:
• The app crashes due to high memory consumption when attempting to pause and resume uploads of files larger than 2GB with the chunk size set to 0.
• The app is not running in the background when I set the chunk size other than 0, eg: If I set the chunk size as 20MB, the app will upload in the background until 20MB. Then pauses and waits for the app to come in foreground to upload the next chunk.

Code Snippet:
func initializeTusClient(){
do {
let identifier = "com.workflowlabs.newsflowkmp.tus"
let tusClient = try TUSClient(
server: URL(string: Urls().uploadFile)!,
sessionIdentifier: "TUS DEMO",
sessionConfiguration: .background(withIdentifier: identifier),
storageDirectory: URL(string: "/TUS")!,
chunkSize: 0 // This causes high memory usage for large files when uploads are paused and resumed.
)
Self.uploadCommon = UploadCommonIosImpl(tusClient: tusClient)
logDebug(message: "Upload initiated", tag: "UploadTusIos")
} catch let error {
logError(error: "Failed to create tusClient instance")
logError(error: error)
}
}

Environment:
• iOS version: 18.3.2
• TusKit version: 3.4.3
• Device: iPhone 11

Additional Context:
• Setting the chunk size to a non-zero value avoids the crash but results in the upload pausing when the app goes into the background.
• Any insights on how to balance background upload continuation with memory usage would be appreciated.

For old code snippets please refer to Pr #195

Error logs
#3 0x000000010143ddbc in UploadDataTask.prepareUploadFile() at /Users/muthuvelekambaranathan/Downloads/NewsFlow2ChatFeatureFinished/NewsFlowKMP/iosApp/Pods/TUSKit/Sources/TUSKit/Tasks/UploadDataTask.swift:186
#4 0x000000010143cd68 in UploadDataTask.run(completed:) at /Users/muthuvelekambaranathan/Downloads/NewsFlow2ChatFeatureFinished/NewsFlowKMP/iosApp/Pods/TUSKit/Sources/TUSKit/Tasks/UploadDataTask.swift:85
#6 0x000000010141bcc4 in closure #1 in Scheduler.checkProcessNextTask() at /Users/muthuvelekambaranathan/Downloads/NewsFlow2ChatFeatureFinished/NewsFlowKMP/iosApp/Pods/TUSKit/Sources/TUSKit/Scheduler.swift:104
Thread 48: EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=2098 MB)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions