Skip to content

fix(barcode-scanner): settle the pending scan() promise on cancel (fix #3560) - #3571

Open
ghostshreyash wants to merge 1 commit into
tauri-apps:v2from
ghostshreyash:fix/barcode-scanner-cancel-settles-scan
Open

fix(barcode-scanner): settle the pending scan() promise on cancel (fix #3560)#3571
ghostshreyash wants to merge 1 commit into
tauri-apps:v2from
ghostshreyash:fix/barcode-scanner-cancel-settles-scan

Conversation

@ghostshreyash

Copy link
Copy Markdown

Fixes #3560.

Bug

On Android, cancel() tore the camera down but never settled the pending scan() promise. In BarcodeScannerPlugin.kt, cancel() called destroy() first, and destroy() sets savedInvoke = null, so the following savedInvoke?.reject("cancelled") was a no-op. Frontend code awaiting scan() was stranded forever, which is especially bad in windowed mode where the page background stays transparent.

Fix

Reject the pending invoke before calling destroy(). This is the order the iOS implementation already uses (self.invoke?.reject("cancelled") then destroy()), so both platforms now behave the same: scan() rejects with "cancelled", and cancel() itself resolves.

Verification

Built examples/api for Android (x86_64, debug) and ran it on an Android 16 / API 36 emulator, the same API level as in the report. Scanner view, Scan, then Cancel:

  • Before (unpatched build) the console shows only cancelled, which is the example's own cancelScan() message. The scan() promise never settled, so its .catch never ran.
  • After (this branch) the console shows { "message": "cancelled" } from scan().catch(...) followed by cancelled. The camera is released in both cases.

Changeset added for barcode-scanner and barcode-scanner-js (patch).

…tauri-apps#3560)

On Android, cancel() called destroy() first, and destroy() sets
savedInvoke to null, so the savedInvoke?.reject("cancelled") that
follows was a no-op. The pending scan() promise was never settled and
callers awaiting it were stranded, which is especially bad in windowed
mode where the page background stays transparent.

Reject the pending invoke before tearing the camera down, matching the
order the iOS implementation already uses.
@ghostshreyash
ghostshreyash requested a review from a team as a code owner September 8, 2026 05:03
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Package Changes Through 4f483e4

There are 4 changes which include barcode-scanner with patch, barcode-scanner-js with patch, http with patch, http-js with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.47 2.0.48
api-example-js 2.0.43 2.0.44
barcode-scanner 2.4.6 2.4.7
barcode-scanner-js 2.4.6 2.4.7
http 2.6.0 2.6.1
http-js 2.6.0 2.6.1

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

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.

[barcode-scanner] Android: cancel() never settles the pending scan() promise (destroy() nulls savedInvoke first)

1 participant