Repository navigation
fix(client): send CLOSE when a subscription handle is closed - #566
Merged
Merged
Conversation
Closing the handle from NostrRelayClient.subscribe(ReqMessage, ...) now drops the listener and sends ["CLOSE", id] once, fire-and-forget. Relays no longer accumulate open REQs until they refuse new ones. The relay's CLOSED reply to a client-initiated CLOSE does not complete an in-flight send(). Raw-JSON subscriptions are unchanged (no parsed id).
This was referenced Nov 25, 2026
Merged
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
NostrRelayClient's subscription handle only removed the local listener and never sentCLOSE, despiteRelayConnection.subscribedocumenting that the handle "cancels the subscription when closed". Relays (strfry, limit 200) accumulated open REQs and started refusing them withtoo many concurrent REQs(took down imani-support-agent's support-snapshot service, worked around in imani-support-agent#13).Changes
subscribe(ReqMessage, ...)handle: removes the listener, then sends["CLOSE", id]fire-and-forget via the gated session write. Idempotent (second close is a no-op). Never waits for a reply. Failure or a closed session is only logged at debug.send()slot. That was the concern in the oldRelaySubscription.close()javadoc ("sending one would consume the slot the next subscription needs"). In addition, the relay'sCLOSEDreply to a client-initiated CLOSE is now kept from completing an unrelated in-flightsend()(it is still routed by id, to the already-removed listener, so nobody sees it).subscribe(String, ...)is unchanged: no id is parsed, so no CLOSE is sent (guessing an id from unvalidated JSON could close another subscription). Documented inline.RelaySubscription.close()javadoc updated. CHANGELOG[Unreleased]entry.Tests
New
NostrRelayClientSubscriptionCloseTest:["CLOSE","sub-1"]mvn -pl nostr-java-client test: Tests run: 89, Failures: 0, Errors: 0, Skipped: 0. Fullmvn -q verifynot run.Follow-up
After this ships in a release, imani-support-agent should bump nostr-java and remove the
RelayPoolGateway.sendCloseworkaround from PR #13 (otherwise it sends a duplicate CLOSE, harmless but redundant).