Repository navigation
Do not publish a half-initialized app instance on cancellation. - #49
Open
TheBlackBit wants to merge 1 commit into
Open
TheBlackBit wants to merge 1 commit into
TheBlackBit wants to merge 1 commit into
Conversation
TheBlackBit
force-pushed
the
fix/app-init-not-cancellable
branch
from
November 20, 2026 01:17
1e74f77 to
edd2579
Compare
`App.getInstance()` stored `app` before `initialize()` had finished. If the initialization was cancelled, the next caller got that half-built instance back and failed with `kotlin.UninitializedPropertyAccessException` on `presentmentSource`. A retry after a partial initialization failed with `KeyExistsStorageException`, because the storage kept tables it had created on disk and forgot them in memory. Run the initialization in `NonCancellable` and publish `app` only after it has completed. This covers cancellation only: a retry after `initialize()` throws is not addressed. Test: On a Samsung SM-S928B (Android 17) I force-stopped the wallet and requested a credential from Chrome through the Digital Credentials API. Without this change the wallet process died with the exception above; with it there was no crash. I ran this on top of the head of pull request 48, because `main` does not build against the Multipaz SDK in my local Maven repository. On that build `./gradlew :androidApp:testDebugUnitTest` and `./gradlew :androidApp:lintDebug` both pass. Signed-off-by: Ever Morales <ever.morales@koombea.com>
TheBlackBit
force-pushed
the
fix/app-init-not-cancellable
branch
from
November 20, 2026 01:20
edd2579 to
258141e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
App.getInstance()storesappbeforeinitialize()has finished. If the initialization is cancelled, the next caller gets that half-built instance back and the wallet crashes.What happens
Cold start of the wallet by a Digital Credentials presentment request:
adb shell am force-stop org.multipaz.wallet.android.dev.A retry after a partial initialization can fail differently, with
KeyExistsStorageException: Record with key='AndroidKeystoreSecureArea' (table '_SCHEMA') already exists: the storage kept tables it had created on disk and forgot them in memory. I saw this one on 2026-11-09 and theUninitializedPropertyAccessExceptionon 2026-11-18, on the same phone.The change
Run the initialization in
NonCancellableand publishapponly after it has completed. One file,App.kt.This covers cancellation only. If
initialize()throws,appis no longer published, but tables it already created on disk remain and a retry could still fail withKeyExistsStorageException; I did not test that path and it is not addressed here. A caller that is cancelled now still waits for the initialization to finish. There is no automated test: theAppsingleton makes one hard to write, so the only protection is the manual run below.Checked
./gradlew :androidApp:testDebugUnitTestand./gradlew :androidApp:lintDebugpass.