fix: bad relay 24h expiry + unsupported relay auto-disconnect#33
Merged
fix: bad relay 24h expiry + unsupported relay auto-disconnect#33
Conversation
Two issues causing relay count to drop from 60 to 6:
1. Bad relay markings were permanent (persisted forever in SharedPrefs).
Transient issues like WebSocket deflater crashes caused relays to
accumulate mid-session failures, get marked bad, and never recover.
Fix:
- Bad relays now expire after 24 hours (BAD_RELAY_EXPIRY_MS)
- _badRelays changed from Set<String> to Map<String, Long> (URL → timestamp)
- Expired entries pruned on isBad()/getBadRelays() and on load
- Old format (StringSet without timestamps) discarded on upgrade,
immediately clearing stale bad relay lists
- BAD_DISCONNECT_SESSIONS raised from 4 to 6 (less aggressive)
- Added clearAllBadRelays() for manual recovery
2. Relays like notify.damus.io (push notification only) don't support
standard Nostr protocol. They respond to every REQ with 'Unsupported
message' NOTICE, wasting subscriptions and polluting the console.
Fix:
- Track consecutive 'unsupported'/'not supported' NOTICEs per relay
- After 3 unsupported notices, disconnect and block the relay URL
- Counter resets when relay sends a valid event or EOSE
- Blocked URLs cleared on disconnectAll (account switch)
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.
Summary
Fix relay count dropping from 60 to ~6 over time. Two root causes.
Problem
Bad relay markings are permanent. The HealthTracker persists bad relays to SharedPreferences with no expiry. Transient issues (WebSocket deflater crashes from concurrent sends, network blips) cause mid-session disconnects. After 4 disconnects, a relay is marked bad forever. Over time, most relays get marked bad.
Push notification relays waste subscriptions. Relays like
notify.damus.ioappear in relay lists but don't support standard Nostr protocol. Every REQ triggers "Unsupported message" NOTICE, polluting the console and wasting subscription capacity.Changes
RelayHealthTracker
_badRelayschanged fromSet<String>toMap<String, Long>(URL → timestamp)isBad()andgetBadRelays()prune expired entriesBAD_DISCONNECT_SESSIONSraised from 4 to 6 (less aggressive marking)clearAllBadRelays()for manual recoveryRelayPool — unsupported relay detection
disconnectAll()(account switch)Testing
notify.damus.ioin relay list → verify it gets auto-disconnected after 3 notices