Skip to content

fix: crash when changing rgs server#880

Open
jvsena42 wants to merge 13 commits intomasterfrom
fix/rgs-crash
Open

fix: crash when changing rgs server#880
jvsena42 wants to merge 13 commits intomasterfrom
fix/rgs-crash

Conversation

@jvsena42
Copy link
Copy Markdown
Member

@jvsena42 jvsena42 commented Apr 1, 2026

Description

This PR fixes an ANR (Application Not Responding) crash on the RGS Server settings screen caused by catastrophic regex backtracking.

The URL_PATTERN regex had a nested quantifier (/[-a-z\d%_.~+]*)* that triggered exponential backtracking in Android's ICU regex engine. Since isValidURL ran on every keystroke on the main thread via computeState, certain URL inputs would freeze the app for 5+ seconds, triggering an ANR.

This PR:

  1. Replaces the monolithic URL regex with java.net.URI parsing + simple hostname/path patterns (matching the approach already used in ElectrumConfigViewModel)
  2. Adds URL reachability validation via UrlValidator before restarting the node, preventing invalid RGS URLs from being saved
  3. Adds unit tests for both RgsServerViewModel and LightningRepo.restartWithRgsServer, including timeout-based tests to detect backtracking regressions
  4. Add a 1 second debounce

Preview

Screen_recording_20260401_140552.webm

QA Notes

1. No ANR when typing URLs

  1. Go to Settings > Advanced > RGS Server
  2. Type https://rapidsync.lightningdevkit.org/snapshot character by character
  3. Expected: No freeze or ANR, UI remains responsive

2. Invalid RGS host shows error toast

  1. Enter https://rapidsync.lightningdevkit.org/snapdsadaDSF as RGS URL
  2. Tap Connect
  3. Expected: Error toast appears (URL unreachable), app does not crash

3. Valid RGS host connects successfully

  1. Enter the default RGS URL or another valid one
  2. Tap Connect
  3. Expected: Success toast appears

4. Unit tests

  • ./gradlew testDevDebugUnitTest --tests "to.bitkit.ui.settings.advanced.RgsServerViewModelTest" — 19 tests pass
  • ./gradlew testDevDebugUnitTest --tests "to.bitkit.repositories.LightningRepoTest" — all tests pass including 4 new RGS tests

@jvsena42 jvsena42 self-assigned this Apr 1, 2026
@jvsena42 jvsena42 marked this pull request as draft April 1, 2026 14:28
jvsena42 added 4 commits April 1, 2026 11:56
… that caused catastrophic backtracking in the ICU regex engine on Android, running on every keystroke on the main thread
@jvsena42
Copy link
Copy Markdown
Member Author

jvsena42 commented Apr 1, 2026

jvsena@Joaos-MacBook-Air ~ % ping https://rapidsync.lightningdevkit/snapshot
ping: cannot resolve https://rapidsync.lightningdevkit/snapshot: Unknown host
jvsena@Joaos-MacBook-Air ~ % ping https://rapidsync.lightningdevkit/snapshot/0
ping: cannot resolve https://rapidsync.lightningdevkit/snapshot/0: Unknown host
jvsena@Joaos-MacBook-Air ~ % 

LDK RGS is not reachable for me

@ovitrif ovitrif added this to the 2.2.0 milestone Apr 1, 2026
@jvsena42
Copy link
Copy Markdown
Member Author

jvsena42 commented Apr 1, 2026

the correct address is https://rapidsync.lightningdevkit.org/snapshot/

@jvsena42 jvsena42 marked this pull request as ready for review April 1, 2026 17:15
@jvsena42 jvsena42 requested review from ovitrif and pwltr April 1, 2026 17:15
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