taler-android

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

login-hangs-forever-on-a-silent-backend.md (3682B)


      1 # A backend that never answers leaves the login form behind a spinner forever
      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-high -- the terminal becomes unusable with no way out
      6 short of killing the app, and the screen it is stuck on says nothing at all,
      7 so a cashier cannot tell it apart from a slow network.
      8 
      9 **Where:**
     10 `taler-kotlin-android/src/main/java/net/taler/common/HttpUtils.kt:71` (the
     11 timeouts) and
     12 `merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigFragment.kt`
     13 (the modal that covers the form while `isSubmitting` is true).
     14 
     15 **Found by:** `pos-simulator`, scenario `backend_never_answers`, against
     16 `backend/mockd.py --profile hang`.
     17 
     18 ## What happens
     19 
     20 Point the terminal at a merchant backend that accepts the TCP connection,
     21 completes the TLS handshake, and then never sends a response. Fill the login
     22 form in and press Connect.
     23 
     24 The form is covered by a modal dialog containing a spinner and nothing else.
     25 Three minutes later it is still there:
     26 
     27 ```
     28 hung-request-never-gives-up: the login form was still covered by its modal
     29 spinner 180s after submitting to a backend that never answers, with nothing to
     30 cancel and nothing to read
     31 blank-screen: 8 nodes, none labelled or tappable
     32 after a back press: nothing readable
     33 ```
     34 
     35 The second line is the accessibility consequence of the first: the dialog is
     36 the focused window, it contains one `CircularProgressIndicator` and no text, so
     37 a screen reader announces nothing whatsoever. The third is that there is no way
     38 out -- `Dialog(onDismissRequest = {})` swallows the back press, and the dialog
     39 has no button.
     40 
     41 ## Why
     42 
     43 Nothing gives up. `createDefaultHttpClient` installs `HttpTimeout` with every
     44 timeout set to infinity:
     45 
     46 ```kotlin
     47 install(HttpTimeout) {
     48     requestTimeoutMillis = INFINITE_TIMEOUT_MS
     49     socketTimeoutMillis = INFINITE_TIMEOUT_MS
     50     connectTimeoutMillis = INFINITE_TIMEOUT_MS
     51 }
     52 ```
     53 
     54 So `fetchLimitedAccessToken` suspends until the peer closes the connection,
     55 which a hung peer does not do. `isSubmitting` is only cleared in the `catch`
     56 blocks of `submitManualConfig` and in `onConfigUpdate`, and neither runs.
     57 
     58 This is not the same thing as an unreachable host, which fails quickly and
     59 correctly (`login_unknown_host` passes): it needs a peer that accepts and then
     60 goes quiet -- a backend under load, a half-open connection a NAT has forgotten,
     61 or a captive portal.
     62 
     63 The infinite timeouts are deliberate in the library: the wallet needs them for
     64 long-polling, where a request is *meant* to hang until something happens. The
     65 terminal's login is not long-polling.
     66 
     67 ## Reproducing it
     68 
     69 ```bash
     70 cd /tmp/taler-pos-sim/driver && . ../env.sh
     71 python3 backend/mockd.py --profile hang --port 19443 &
     72 python3 suite.py backend_never_answers
     73 ```
     74 
     75 ## The fix
     76 
     77 Two parts, and only the first is strictly necessary.
     78 
     79 A finite timeout on the requests the login makes. Ktor's `HttpTimeout` can be
     80 set per request, so this need not change the shared client and need not affect
     81 whatever long-polls:
     82 
     83 ```kotlin
     84 httpClient.post(tokenUrl) {
     85     timeout { requestTimeoutMillis = 30_000 }
     86     ...
     87 }
     88 ```
     89 
     90 and the same for the `GET` in `fetchPosConfig` and the backend `config` call.
     91 
     92 A way out of the modal. The dialog already exists; giving it a cancel button
     93 that clears `isSubmitting` -- and, ideally, cancels the coroutine -- turns an
     94 unrecoverable state into an ordinary one. It also fixes the accessibility side,
     95 because the button carries a label.
     96 
     97 No patch here: the timeout value is a product decision, and which of the three
     98 calls should get which value is worth a conversation rather than a guess.