fix: prevent electrum connect ANR in url regex#1077
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR prevents malformed Electrum server input from blocking the app. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| app/src/main/java/to/bitkit/ui/settings/advanced/ElectrumConfigViewModel.kt | Precompiles a linear hostname regex and moves Connect and scan validation to the background dispatcher. |
| app/src/main/java/to/bitkit/ui/settings/advanced/RgsServerViewModel.kt | Replaces the matching hostname regex shape with a linear precompiled pattern. |
| app/src/test/java/to/bitkit/ui/settings/advanced/ElectrumConfigViewModelTest.kt | Adds hostname validation and non-blocking Connect tests. |
| app/src/test/java/to/bitkit/ui/settings/advanced/RgsServerViewModelTest.kt | Adds a timeout test for long dotless RGS hostnames. |
Reviews (1): Last reviewed commit: "chore: rename changelog fragment" | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27a021e9e7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Member
Author
|
Tested 1 only with Unit tests |
jvsena42
enabled auto-merge
July 15, 2026 11:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1068
This PR fixes an ANR that could freeze the app when tapping Connect on the Electrum server settings screen.
Description
Play Vitals reported an ANR where URL validation ran a hostname regex on the main thread and blocked input dispatch. Two things caused it:
The fix rewrites the hostname pattern to an equivalent form without nested quantifiers (linear matching, verified to accept and reject the same inputs), hoists it into a compiled constant instead of recompiling it on every call, and moves the Connect and scan validation onto the background dispatcher.
The same regex shape also existed in the Rapid Gossip Sync server validation. It already ran off the main thread so it could not ANR, but it was the same class of issue and got the same linear rewrite.
Preview
electrum-valid.webm
electrum-invalid.webm
rgs.webm
QA Notes
OBS: run in mainnetDebug for using main net electrum addresses without errors
Manual Tests
electrum.blockstream.info/50002) → tap Connect: connects successfully.regression:Settings → Advanced → Rapid Gossip Sync server → paste a long URL with a dotless host: no freeze and Connect stays disabled.Automated Checks
.localhost acceptance, dotless-host rejection, and the ANR regression (Connect with a long dotless host resolves within a timeout without calling the node restart) inElectrumConfigViewModelTest.kt.RgsServerViewModelTest.kt.