Skip to content

fix: crash when changing rgs server#880

Merged
ovitrif merged 19 commits intomasterfrom
fix/rgs-crash
Apr 2, 2026
Merged

fix: crash when changing rgs server#880
ovitrif merged 19 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
@jvsena42
Copy link
Copy Markdown
Member Author

jvsena42 commented Apr 1, 2026

@piotr-iohk it is probably failing because of the 1s debounce https://github.com/synonymdev/bitkit-android/actions/runs/23861269000/job/69576046177?pr=880

@claude

This comment has been minimized.

ovitrif
ovitrif previously approved these changes Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

utAck

Very nice and thoroughly tested 👏🏻

:shipit:

@ovitrif ovitrif enabled auto-merge April 2, 2026 10:21
@ovitrif

This comment was marked as resolved.

@jvsena42 jvsena42 marked this pull request as draft April 2, 2026 11:32
auto-merge was automatically disabled April 2, 2026 11:32

Pull request was converted to draft

@jvsena42

This comment was marked as resolved.

@jvsena42
Copy link
Copy Markdown
Member Author

jvsena42 commented Apr 2, 2026

Is this expected @jvsena42 ?!

Fixed 06c2835

Screen_recording_20260402_084912.webm

@jvsena42 jvsena42 marked this pull request as ready for review April 2, 2026 11:51
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

tAck

@ovitrif ovitrif merged commit fd1f24b into master Apr 2, 2026
14 of 21 checks passed
@ovitrif ovitrif deleted the fix/rgs-crash branch April 2, 2026 13:48
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.

4 participants