mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-09-19 04:59:59 +00:00
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:
parent
7afab46dc0
commit
411541faf5
@ -531,12 +531,12 @@ object NostrIdentityBridge {
|
|||||||
id = subscriptionId,
|
id = subscriptionId,
|
||||||
handler = { event ->
|
handler = { event ->
|
||||||
if (!resolved && event.kind == NostrKind.METADATA && event.pubkey == pubkeyHex) {
|
if (!resolved && event.kind == NostrKind.METADATA && event.pubkey == pubkeyHex) {
|
||||||
resolved = true
|
|
||||||
try {
|
try {
|
||||||
val profileJson = com.google.gson.JsonParser.parseString(event.content).asJsonObject
|
val profileJson = com.google.gson.JsonParser.parseString(event.content).asJsonObject
|
||||||
val name = profileJson.get("name")?.asString?.takeIf { it.isNotBlank() }
|
val name = profileJson.get("name")?.asString?.takeIf { it.isNotBlank() }
|
||||||
?: profileJson.get("display_name")?.asString?.takeIf { it.isNotBlank() }
|
?: profileJson.get("display_name")?.asString?.takeIf { it.isNotBlank() }
|
||||||
|
|
||||||
|
resolved = true
|
||||||
relayManager.unsubscribe(subscriptionId)
|
relayManager.unsubscribe(subscriptionId)
|
||||||
|
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
GlobalScope.launch(Dispatchers.Main) {
|
||||||
@ -544,6 +544,7 @@ object NostrIdentityBridge {
|
|||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(TAG, "Failed to parse profile for $pubkeyHex: ${e.message}")
|
Log.w(TAG, "Failed to parse profile for $pubkeyHex: ${e.message}")
|
||||||
|
// Don't mark as resolved - let timeout or next event retry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user