-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: asset upload cancellation #1251
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all great job with all the issue investigation. Really strange these cancellations errors are not handled by Ktor in an easier and more graceful manner 🤯
However, my understanding was that we didn't want to allow user's cancellation of any ongoing upload?
If we take this path this will introduce the need of maintenance of all the overriding classes recently added + more room for other edge cases in case Ktor behavior regarding callbacks changes in the near future for example. Therefore I'd also advocate for keeping it simpler and not allow this kind of user interaction while uploading.
But if we still decide to allow it, I'd say I'd feel more comfortable adding some more unit tests to this PR, showing how if the call to the asset repository gets cancelled, halfway through, we will not be forwarding the error to the upper layer.
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
Show resolved
Hide resolved
network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/AssetApiV0.kt
Show resolved
Hide resolved
closing the PR, because of the product decision not to cancel asset upload |
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764
The PR Description
What's new in this PR?
Issues
It looks like somehow Ktor is not doing well with cancellation of request bodies that require some writing to ByteChannel's. The problem seems to be Ktor not working well with CancelationException
In the stacktrace, you can see, where the crash is coming from :
It looks like, when building the request, Ktor lets any other exception up to thread handler expect of IOException()
The issue is also described here , probably much better than above, so refer to it :
awslabs/aws-sdk-kotlin#733
The fix is also taken almost straight from their PR.
Additional to overwriting OkHttpClientEngine in order to inject our own version of RequestBody()
We also had to do similar operation to our StreamAssetContent.kt which overrides OutgoingContent.WriteChannelContent.kt,
which is also being used for updating the asset and also could slip the CancellationException into the thread exception handler and cause our app to crash.
Dependencies (Optional)
If there are some other pull requests related to this one (e.g. new releases of frameworks), specify them here.
Needs releases with:
Testing
Test Coverage (Optional)
How to Test
Briefly describe how this change was tested and if applicable the exact steps taken to verify that it works as expected.
Notes (Optional)
Specify here any other facts that you think are important for this issue.
Attachments (Optional)
Attachments like images, videos, etc. (drag and drop in the text box)
PR Post Submission Checklist for internal contributors (Optional)
PR Post Merge Checklist for internal contributors
References
feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764
.