Skip to content

fix: close nine crash and concurrency paths found after the TestFlight reports - #1015

Merged
romchornyi merged 3 commits into
developfrom
fix/confirmed-crash-fixes
Aug 14, 2026
Merged

fix: close nine crash and concurrency paths found after the TestFlight reports#1015
romchornyi merged 3 commits into
developfrom
fix/confirmed-crash-fixes

Conversation

@romchornyi

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Two crash reports came in from TestFlight 9.0.0 (builds 25 and 28):

Auditing the codebase for the same defect classes turned up five more crash paths reachable from ordinary use, plus four dangerous patterns whose reachability took longer to establish. None of them can be caught by a do/catch: every one is a trap or an abort, not a thrown error.

What was done?

Three commits, readable independently.

fix(payments) — the reported iPad crash. On iPad UIActivityViewController is always presented as a popover, and a popover with neither sourceView nor barButtonItem throws when the presentation begins. The anchor lives in a new dw_presentActivityViewController helper rather than at the call site, because the support-log share had the same gap; both callers come from SwiftUI and have no sender view, so the helper anchors an arrow-less popover at the centre by default and accepts an explicit view or rect when one exists.

fix — five crash paths.

Where What aborts
ExplorePointOfUse.init(row:) Merchant.Type(rawValue:) is the one enum in the file without a catch-all; its nil was passed as a non-optional argument. A merchant category added server-side aborts the app for everyone on the next database sync. type is now optional on Merchant and Atm — unknown stays unknown instead of being mapped onto an existing case.
ExplorePointOfUse.init(row:) No text column in that schema is NOT NULL, and SQLite.swift's subscript for a non-optional Expression is try! get(column) — it aborts on NULL and on a column a synced schema no longer carries. The affected columns now read through try? row.get, as this initializer already did for phone, logoLocation and coverImage.
TimeUtils The NTP reply was indexed at offsets 40-43 with no length check. minimumIncompleteLength is not a floor for UDP, so a runt or rewritten datagram (a captive portal intercepting 123/udp) arrives with no error and traps. Reachable from HomeView.onAppear on every visit.
AccountRepository.all balance.amount from the Coinbase JSON was force-unwrapped through Decimal(string:); unparseable now counts as no balance instead of taking down the accounts screen.
CrowdNodeWebViewController replaceLast(3) assumed the Getting Started route's stack depth; entering from the home shortcut leaves two controllers and removeLast(3) traps. The call site sets the stack directly, and replaceLast clamps n, which also closes the same mismatch in NewAccountViewController.

fix — token refresh and three latent traps. CTXSpendTokenService and CBSecureTokenService stored the in-flight refresh Task in a plain property on a non-isolated class and force-unwrapped it, with real concurrent callers on both sides (CTXSpendAPI funnels every 401 into the first; every Coinbase request reaches the second through refreshTokenIfNeeded). PiggyCardsTokenService already solved this with a private actor, so that actor is promoted to internal and reused by all three rather than copied. Also: locale.decimalSeparator! on the amount-entry path now falls back to "." as the sibling helper in the same file does; the two formatter singletons in Tools take a lock, as the cache beside them already does; and the duplicate-migration-version check throws instead of asserting, so it survives ENABLE_NS_ASSERTIONS = NO in Release and TestFlight and names the cause in the log.

How Has This Been Tested?

  • xcodebuild -workspace DashWallet.xcworkspace -scheme dashpay -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' ARCHS=arm64 build — succeeds.
  • The URL(string:) behaviour behind a sixth reported candidate was checked against the current Foundation parser and did not reproduce, so that one is deliberately not changed.
  • No device or simulator run of the touched flows yet: the CrowdNode path needs an existing linked account, and the Explore paths need a synced database carrying the offending row. The unit-test target is broken on this branch (pre-existing), so nothing here is covered by automated tests.

Worth a reviewer's eye: the Merchant.type / Atm.type optionality ripples into eight comparison sites (m.type == .online and friends). They all keep compiling because comparing an optional against a case is still valid, and a row with an unknown type now reads as "not online" — the behaviour on merchants we can't classify is a product call, not a mechanical one.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

On iPad UIKit presents `UIActivityViewController` as a popover, and a
popover carrying neither `sourceView` nor `barButtonItem` throws
`NSInvalidArgumentException` from `presentationTransitionWillBegin`. A
TestFlight user on 9.0.0 (28) crashed there when tapping "share
address"; iPhone never reaches it because the sheet is modal.

The anchor goes into a `dw_presentActivityViewController` helper instead
of the call site, because the support-log share had the same gap. Both
callers are driven from SwiftUI and have no sender view to point at, so
the helper anchors an arrow-less popover at the centre of the presenting
controller's view by default, and takes an explicit view or rect when
one exists.
Found by auditing the codebase after two TestFlight crash reports. Every
one of them is a trap or an abort, so none can be caught by the
`do`/`catch` the surrounding code already has.

Explore database (`ExplorePointOfUse.init(row:)`), two of them. The
merchant `type` column was resolved through `Merchant.Type(rawValue:)`,
the one enum in that file without a catch-all, and the resulting `nil`
was passed as a non-optional initializer argument — so a value the
backend adds server-side, such as a new merchant category, aborts the
app for everyone on the next database sync. `type` is now optional on
`Merchant` and `Atm`: unknown stays unknown rather than being mapped
onto an existing case. Separately, no text column in that schema is
declared NOT NULL, and SQLite.swift's subscript for a non-optional
`Expression` is `try! get(column)`, which aborts on NULL and on a column
a synced schema no longer carries. `name`, `territory`, `type`,
`source`, `merchantId`, `savingsPercentage` and `active` now read
through `try? row.get`, which is what this initializer already did for
`phone`, `logoLocation` and `coverImage`.

NTP parsing (`TimeUtils`). The reply was indexed at offsets 40-43 with
no length check. A datagram connection delivers whatever arrived —
`minimumIncompleteLength` is not a floor for UDP — so a runt or
rewritten packet, as a captive portal intercepting 123/udp produces,
arrives with no error and traps. The packet is copied into an array so
the offsets are positions within it rather than absolute `Data`
indices, and short replies are discarded.

Coinbase accounts (`AccountRepository.all`). `balance.amount` arrives as
a string in the JSON response and was force-unwrapped through
`Decimal(string:)`; anything unparseable now counts as no balance
instead of taking down the accounts screen.

CrowdNode navigation (`CrowdNodeWebViewController`). `replaceLast(3)`
after a successful online-account link assumed the Getting Started
route's stack depth. Entering from the home shortcut, where the portal
is the navigator's root, leaves two controllers, and `removeLast(3)`
traps. Both routes end at the portal with nothing behind it, so the call
site sets the stack directly. `replaceLast` also clamps `n` to the stack
depth, which closes the same mismatch in `NewAccountViewController`,
reachable when `getRootVC()` opens on the new-account screen.
The same audit turned up four dangerous patterns whose reachability took
longer to establish. All four ship in the current scheme.

Token refresh. `CTXSpendTokenService` and `CBSecureTokenService` each
stored the in-flight refresh in a plain property on a non-isolated class
and then force-unwrapped it. Concurrent callers exist for both:
`CTXSpendAPI` funnels every 401 into the first, and every Coinbase
request reaches the second through `refreshTokenIfNeeded`. Two callers
can each see no task in flight, start their own, and clobber the stored
reference; a competing `defer` clearing it between the write and the
force-unwrap is a crash. `PiggyCardsTokenService` already solved this
with a private actor, so that actor is promoted to internal and reused
by all three rather than copied. It now takes the service label for its
log line and a throwing `Void` closure instead of the `Bool` contract
that was specific to PiggyCards; the write-only `isRefreshing` flag is
gone.

Locale separator (`String.attributedAmountForLocalCurrency`).
`locale.decimalSeparator!` sits on the amount-entry path, which
`AmountInputControl.reloadData` runs on every keystroke. It now falls
back to "." exactly as the sibling helper 48 lines above it does.

Formatter singletons (`Tools`). `_fiatFormatter` and `_decimalFormatter`
were built and replaced without synchronization, while
`_cachedFormatters` beside them is lock-protected.
`CoinJoinMixingTxSet.fiatAmount` reaches them from the background queue
`HomeViewModel.reloadTxDataSource` runs on, concurrently with main-
thread formatting everywhere else. They take a second lock rather than
the existing one, because the `fiatFormatter` getter calls
`fiatFormatter(currencyCode:)`, which takes the existing lock, and
`NSLock` is not recursive.

Migration versions (`DatabaseConnection`). The duplicate-version check
was an `assert`, compiled out under `ENABLE_NS_ASSERTIONS = NO` in
Release and TestFlight — the builds where a duplicate would actually
ship. `schema_migrations.version` is UNIQUE, so the insert fails there
regardless, but as an opaque constraint error. Throwing instead names
the cause in the log `AppDelegate` already writes.
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@romchornyi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c81b358-a498-4b1a-8436-de2ddbcde39e

📥 Commits

Reviewing files that changed from the base of the PR and between ddec2a4 and dcd6e82.

📒 Files selected for processing (13)
  • DashWallet/Sources/Application/Tools.swift
  • DashWallet/Sources/Categories/String+DashWallet.swift
  • DashWallet/Sources/Categories/UIViewController+DashWallet.swift
  • DashWallet/Sources/Infrastructure/Database/DatabaseConnection.swift
  • DashWallet/Sources/Models/Coinbase/Accounts/AccountRepository.swift
  • DashWallet/Sources/Models/Coinbase/Auth/Services/CBSecureTokenService.swift
  • DashWallet/Sources/Models/Explore Dash/Model/Entites/ExplorePointOfUse.swift
  • DashWallet/Sources/Models/Explore Dash/Services/DashSpend/CTX/CTXSpendTokenService.swift
  • DashWallet/Sources/Models/Explore Dash/Services/DashSpend/PiggyCards/PiggyCardsTokenService.swift
  • DashWallet/Sources/UI/CrowdNode/Online/CrowdNodeWebViewController.swift
  • DashWallet/Sources/UI/Payments/Landing/PaymentsLandingHostingController.swift
  • DashWallet/Sources/UI/Views/Navigation/BaseNavigationController.swift
  • DashWallet/Sources/Utils/TimeUtils.swift

Comment @coderabbitai help to get the list of available commands.

@romchornyi
romchornyi requested a review from llbartekll August 13, 2026 17:13

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@romchornyi
romchornyi merged commit 1328875 into develop Aug 14, 2026
2 checks passed
@romchornyi
romchornyi deleted the fix/confirmed-crash-fixes branch August 14, 2026 11:35
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.

3 participants