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

Crash on Coroutine Cancellation #704

Closed
sdhuka opened this issue Sep 23, 2022 · 3 comments
Closed

Crash on Coroutine Cancellation #704

sdhuka opened this issue Sep 23, 2022 · 3 comments
Assignees
Labels
bug This issue is a bug.

Comments

@sdhuka
Copy link

sdhuka commented Sep 23, 2022

Describe the bug

SDK okhttp client occasioanlly throws android runtime exception on coroutine cancellation. Could this be caught by the sdk and passed on to the caller instead of crashing the app?

Expected behavior

Exception should be caugth and passed to the caller.

Current behavior

App crashes with below exception

--------- beginning of crash
09-23 02:39:25.241 18824 18945 E AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
09-23 02:39:25.241 18824 18945 E AndroidRuntime: Process: com.amplifyframework.storage.s3.test, PID: 18824
09-23 02:39:25.241 18824 18945 E AndroidRuntime: java.util.concurrent.CancellationException: Job was cancelled
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.ExceptionsKt.CancellationException(Exceptions.kt:22)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at aws.smithy.kotlin.runtime.http.engine.CoroutineUtilsKt$attachToOuterJob$cleanupHandler$1.invoke(CoroutineUtils.kt:39)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at aws.smithy.kotlin.runtime.http.engine.CoroutineUtilsKt$attachToOuterJob$cleanupHandler$1.invoke(CoroutineUtils.kt:37)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.InvokeOnCancelling.invoke(JobSupport.kt:1457)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.notifyCancelling(JobSupport.kt:1499)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.tryMakeCancelling(JobSupport.kt:795)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.makeCancelling(JobSupport.kt:755)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.cancelImpl$kotlinx_coroutines_core(JobSupport.kt:671)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.parentCancelled(JobSupport.kt:637)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.ChildHandleNode.invoke(JobSupport.kt:1465)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.notifyCancelling(JobSupport.kt:1499)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:900)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:863)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.cancelMakeCompleting(JobSupport.kt:696)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.cancelImpl$kotlinx_coroutines_core(JobSupport.kt:667)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.cancelInternal(JobSupport.kt:632)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.JobSupport.cancel(JobSupport.kt:617)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.CoroutineScopeKt.cancel(CoroutineScope.kt:287)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at kotlinx.coroutines.CoroutineScopeKt.cancel$default(CoroutineScope.kt:285)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.worker.BaseTransferListenableWorker.onStopped(BaseTransferListenableWorker.kt:106)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.ListenableWorker.stop(ListenableWorker.java:283)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.worker.RouterWorker.onStopped(RouterWorker.kt:89)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.ListenableWorker.stop(ListenableWorker.java:283)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.WorkerWrapper.interrupt(WorkerWrapper.java:397)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.Processor.interrupt(Processor.java:340)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.Processor.stopAndCancelWork(Processor.java:212)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.utils.CancelWorkRunnable.cancel(CancelWorkRunnable.java:74)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.utils.CancelWorkRunnable$3.runInternal(CancelWorkRunnable.java:186)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.utils.CancelWorkRunnable.run(CancelWorkRunnable.java:61)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.testing.SynchronousExecutor.execute(SynchronousExecutor.java:30)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.utils.SerialExecutor.scheduleNext(SerialExecutor.java:55)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.utils.SerialExecutor.execute(SerialExecutor.java:46)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.testing.TestWorkManagerImpl$1.executeOnBackgroundThread(TestWorkManagerImpl.java:80)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at androidx.work.impl.WorkManagerImpl.cancelUniqueWork(WorkManagerImpl.java:465)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.TransferRecord.pause$aws_storage_s3_debug(TransferRecord.kt:198)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.TransferManager.pause(TransferManager.kt:184)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.service.AWSS3StorageService.pauseTransfer(AWSS3StorageService.kt:180)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.operation.AWSS3StorageUploadFileOperation.pause(AWSS3StorageUploadFileOperation.java:155)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.AWSS3StorageUploadTest.lambda$testUploadFileIsResumable$4(AWSS3StorageUploadTest.java:224)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.-$$Lambda$AWSS3StorageUploadTest$hqW_Es6aBIRMGNJnIljsTTo1hd8.accept(Unknown Source:6)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.operation.AWSS3StorageUploadFileOperation$UploadTransferListener.onProgressChanged(AWSS3StorageUploadFileOperation.java:200)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater.updateProgress$lambda-11$lambda-10(TransferStatusUpdater.kt:135)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.TransferStatusUpdater.lambda$skQZ5NJBbXVDCZQXGyEaWW91ZEM(Unknown Source:0)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.amplifyframework.storage.s3.transfer.-$$Lambda$TransferStatusUpdater$skQZ5NJBbXVDCZQXGyEaWW91ZEM.run(Unknown Source:8)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:883)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:100)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:237)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7971)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
09-23 02:39:25.241 18824 18945 E AndroidRuntime: Caused by: kotlinx.coroutines.JobCancellationException: Job was cancelled; job=JobImpl{Cancelled}@d6b3ef4

Steps to Reproduce

  • Make an S3 service, we repro it on multipart upload
  • Cancel the coroutine while the request is in progress
  • Try few times and you will observer the crash

Possible Solution

Catch the cancellation exception and return it to the caller.

Context

No response

AWS Kotlin SDK version used

0.17.0-beta

Platform (JVM/JS/Native)

Native

Operating System and version

Android 28

@sdhuka sdhuka added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 23, 2022
@aajtodd
Copy link
Collaborator

aajtodd commented Sep 23, 2022

I was able to reproduce this fairly easily. Will get this prioritized and fixed. Thanks.

@lauzadis
Copy link
Member

Fixed in smithy-lang/smithy-kotlin#708, it will be included in this week's release. Thanks for the report!

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants