fix(nostr): prevent subscription leak on JSON parse failure

Move resolved=true after successful parse so timeout cleanup still
runs if metadata content is invalid JSON. Fixes dangling subscriptions
and permanently pending pubkeys.
This commit is contained in:
Andrés Villagrán 2026-01-15 04:14:48 -03:00
parent 7afab46dc0
commit 411541faf5

View File

@ -531,12 +531,12 @@ object NostrIdentityBridge {
id = subscriptionId,
handler = { event ->
if (!resolved && event.kind == NostrKind.METADATA && event.pubkey == pubkeyHex) {
resolved = true
try {
val profileJson = com.google.gson.JsonParser.parseString(event.content).asJsonObject
val name = profileJson.get("name")?.asString?.takeIf { it.isNotBlank() }
?: profileJson.get("display_name")?.asString?.takeIf { it.isNotBlank() }
resolved = true
relayManager.unsubscribe(subscriptionId)
GlobalScope.launch(Dispatchers.Main) {
@ -544,6 +544,7 @@ object NostrIdentityBridge {
}
} catch (e: Exception) {
Log.w(TAG, "Failed to parse profile for $pubkeyHex: ${e.message}")
// Don't mark as resolved - let timeout or next event retry
}
}
}