taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

config-fetch-failure-strands-the-spinner.md (4123B)


      1 # A failed configuration fetch leaves the terminal on its spinner for good
      2 
      3 > **Fixed on master** (checked 2026-11-08, commit `24f7b249`). See [STATUS.md](STATUS.md) for the fix and the test that pins it.
      4 
      5 **Severity:** medium -- the terminal is stranded on a screen that says it is
      6 working, after it has already been told it is not. The only way on is to guess
      7 that the back button does something.
      8 
      9 **Where:**
     10 `merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigFetcherFragment.kt`.
     11 
     12 **Found by:** `pos-simulator`, scenario `provision_setup_uri_malformed`, with a
     13 setup URI that names no host.
     14 
     15 ## What happens
     16 
     17 Deliver a `taler-pos://` setup URI with an empty host:
     18 
     19 ```
     20 taler-pos:///instances/sandbox#secret-token:V69RBF5QCYC1GQZ...
     21 ```
     22 
     23 The terminal accepts it, navigates to its "Fetching configuration…" screen,
     24 fails, and says so:
     25 
     26 ```
     27 'Taler POS': 'Error: The configuration JSON is malformed' ['OK']
     28 ```
     29 
     30 Dismiss that, and the spinner is still there. It stays there. The scenario
     31 waits twelve seconds and then records
     32 `stuck-fetching-after-bad-uri: a setup URI with no host left the terminal
     33 fetching configuration forever`; by hand it is still spinning minutes later.
     34 
     35 ## Why
     36 
     37 `ConfigFetcherFragment` navigates on success and only on success:
     38 
     39 ```kotlin
     40 configManager.configUpdateResult.observe(viewLifecycleOwner) { result ->
     41     when (result) {
     42         null -> return@observe
     43         is ConfigUpdateResult.Error -> {
     44             requireActivity().showPosError(result.msg)       // and nothing else
     45         }
     46         is ConfigUpdateResult.Success -> {
     47             if (!navigating) {
     48                 navigating = true
     49                 (requireActivity() as MainActivity).navigateToInitialOrderScreen()
     50             }
     51         }
     52     }
     53 }
     54 ```
     55 
     56 The error branch shows a dialog and leaves the fragment where it is. The screen
     57 behind the dialog is a `CircularProgressIndicator` and the words "Fetching
     58 configuration…", which is now a lie: nothing is being fetched and nothing will
     59 be.
     60 
     61 Back does get out of it -- `handleExitRequest` falls through to
     62 `navigateBack()`, which pops to whatever was underneath -- but nothing on
     63 screen says so, and on a first run there may be nothing underneath, in which
     64 case `navigateBack` calls `finish()` and the app closes.
     65 
     66 ## The second half: the URI should not have been accepted
     67 
     68 `MainActivity.handleSetupIntent` guards on `data.host ?: return`, which does
     69 not catch this: `Uri.parse("taler-pos:///instances/sandbox#token").host` is the
     70 empty string, not null. So the terminal builds `https:///instances/sandbox`,
     71 asks for it, and gets a failure it then mis-describes as malformed JSON --
     72 `ConfigManager.fetchConfig` uses `config_error_malformed` as the catch-all for
     73 every exception that is not a `ClientRequestException`.
     74 
     75 Eight other malformed setup URIs in the same scenario -- no token, no instance,
     76 an empty instance, a blank token, the wrong scheme, and three shapes of
     77 `#username=&password=` -- are all correctly ignored, leaving the login form
     78 usable. The empty host is the one that gets through.
     79 
     80 ## Reproducing it
     81 
     82 ```bash
     83 cd /tmp/taler-pos-sim/driver && . ../env.sh
     84 python3 suite.py provision_setup_uri_malformed
     85 ```
     86 
     87 or by hand:
     88 
     89 ```bash
     90 adb shell am start -a android.intent.action.VIEW \
     91   -d 'taler-pos:///instances/sandbox#secret-token:anything' \
     92   -n net.taler.merchantpos/.MainActivity
     93 ```
     94 
     95 ## The fix
     96 
     97 Two independent changes, neither of which is a one-liner, so no patch:
     98 
     99 * `ConfigFetcherFragment` should leave the fetching screen when the fetch
    100   fails -- back to the configuration screen, which is where the user can do
    101   something about it. `MainActivity.onStart` already routes an invalid config
    102   there, so the destination exists.
    103 * `handleSetupIntent` should reject an empty host as well as a null one, and
    104   `ConfigManager`'s catch-all deserves a second look while someone is in
    105   there: "The configuration JSON is malformed" is what the terminal says about
    106   a hostname it cannot resolve, a TLS failure and a genuinely malformed reply
    107   alike. See `pos-config-url-percent-encodes-the-separator.md` for the other
    108   thing in that method.