Skip to content

Allow in-progress form upload to be interrupted on cancel#7203

Open
grzesiek2010 wants to merge 9 commits into
getodk:masterfrom
grzesiek2010:COLLECT-7188
Open

Allow in-progress form upload to be interrupted on cancel#7203
grzesiek2010 wants to merge 9 commits into
getodk:masterfrom
grzesiek2010:COLLECT-7188

Conversation

@grzesiek2010

@grzesiek2010 grzesiek2010 commented Apr 23, 2026

Copy link
Copy Markdown
Member

Closes #7188

Why is this the best possible solution? Were any other approaches considered?

In #7008 we reworked the process of uploading filled forms manually by replacing the old Android AsyncTask with coroutines. The old approach was checking if the task is active at the beginning of every iteration (for every selected form) and we implemented the same behavior in the coroutine-based approach. However, it turns out that the old AsyncTask, when canceled, was also interrupting the worker thread, which had the effect of canceling a form upload that was already in progress (mid-upload). We missed that in the new approach, and now I have fixed it by using runInterruptible.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

We need to test the same things as in #7008.

Do we need any specific form for testing your changes? If so, please attach one.

Any form.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@grzesiek2010
grzesiek2010 marked this pull request as ready for review April 23, 2026 20:07
@grzesiek2010
grzesiek2010 requested a review from seadowg April 28, 2026 21:19
@grzesiek2010
grzesiek2010 requested a review from seadowg May 12, 2026 12:16

@seadowg seadowg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grzesiek2010
grzesiek2010 force-pushed the COLLECT-7188 branch 2 times, most recently from 6ad8524 to 680affb Compare June 22, 2026 16:55
@grzesiek2010
grzesiek2010 requested a review from seadowg June 23, 2026 08:12
* Unlike other [FormUploadException]s this should not be reported to the user as an error - it
* simply stops the current submission attempt.
*/
class FormUploadInterruptedException : FormUploadException("Upload interrupted")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can introduce a generalization for this instead that builds on Cancellable - could be a CancellationToken class like this:

class CancellationToken : Cancellable {

    private var cancelled = false

    override fun cancel() {
        cancelled = true
    }

    fun ensureActive() {
        if (isCancelled()) {
            throw CancelledException()
        }
    }
}

Or just something similar!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this a go, but I'd lean towards keeping the current approach. A CancellationToken would complicate the code, and it would decouple cancellation from the coroutine, so we'd drop the built-in mechanism (isCancelled = { !isActive }) we get for free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

It isn't possible to cancel sending a form which was finalized and being sent

2 participants