Commit 7fa89d8
* Guard ArrivalsViewModel.refresh() against out-of-order overlapping refreshes (#1933)
refresh() applied every completed result unconditionally. The 60s poll loop
awaits its suspend refresh() sequentially so it never overlaps itself, but
manualRefresh() and loadMore() each viewModelScope.launch { refresh() } — so a
user refresh (toolbar button, or the alert-dialog dismiss in
ArrivalActionHandlers) can run concurrently with an in-flight poll and finish
out of order. The older-started completion's `loaded.value = data` would then
clobber the fresher result, surfacing a spurious isStale flag or older arrivals
until the next poll corrected it (≤60s). The map snapshot lastLoaded() was
already protected by the repository's compareAndSet (#1932); this closes the
same gap one layer up, in the ViewModel's `loaded` StateFlow.
Fix: a monotonic refreshGeneration bumped at the start of each refresh; a
completion applies its result only while it's still the latest, else it drops
out (no state write, no map-snapshot emit). All reads/writes are confined to the
ViewModel dispatcher — the only suspension in refresh() is the fetch — so a
plain Int needs no synchronization.
Test drives two overlapping refreshes (per-call gates on the fake repository)
completing out of order and asserts the older-started stale completion cannot
overwrite the fresher one; verified red without the guard.
Fixes #1933
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Update lastResponseTime only for the winning refresh completion
Move the lastResponseTime stamp after the latest-wins guard so a superseded
(later-completing) refresh no longer pushes the poll timer past the fresher
completion's timestamp — the poll cadence now measures its 60s interval from the
shown data's arrival. Addresses review feedback on #1934.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c4e00e0 commit 7fa89d8
2 files changed
Lines changed: 60 additions & 5 deletions
File tree
- onebusaway-android/src
- main/java/org/onebusaway/android/ui/arrivals
- test/java/org/onebusaway/android/ui/arrivals
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
106 | 116 | | |
107 | 117 | | |
108 | 118 | | |
109 | | - | |
110 | | - | |
111 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
112 | 123 | | |
113 | 124 | | |
| 125 | + | |
114 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
115 | 131 | | |
116 | 132 | | |
117 | 133 | | |
| |||
Lines changed: 41 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
54 | 60 | | |
55 | 61 | | |
56 | 62 | | |
| |||
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| 81 | + | |
75 | 82 | | |
76 | | - | |
77 | | - | |
| 83 | + | |
| 84 | + | |
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
| |||
254 | 261 | | |
255 | 262 | | |
256 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
257 | 296 | | |
258 | 297 | | |
259 | 298 | | |
| |||
0 commit comments