Skip to content

fix: use multi-filter REQ to avoid subscription explosion#34

Merged
barrydeen merged 1 commit intomainfrom
fix/chunk-as-multi-filter-req
Feb 22, 2026
Merged

fix: use multi-filter REQ to avoid subscription explosion#34
barrydeen merged 1 commit intomainfrom
fix/chunk-as-multi-filter-req

Conversation

@barrydeen
Copy link
Copy Markdown
Owner

Summary

Fix "too many concurrent REQs" errors caused by subscription explosion from filter chunking.

Problem

PR #30 chunked large author lists into separate subscriptions (feed, feed:c1, feed:c2). This multiplied the subscription count per relay — with 500 follows and engagement subs, each relay had 15+ concurrent subscriptions. Relays with limits of 10-20 rejected the excess with "too many concurrent REQs".

Fix

Pack all author chunks as multiple filters within a single REQ instead of multiple subscriptions:

Before: ["REQ","feed",{authors:[1..200]}] + ["REQ","feed:c1",{authors:[201..400]}] + ["REQ","feed:c2",{authors:[401..500]}]
After:  ["REQ","feed",{authors:[1..200]},{authors:[201..400]},{authors:[401..500]}]

One subscription ID, multiple filters. Each individual filter stays ≤200 authors (avoiding "total filter items too large"), but the relay only tracks one subscription.

Changes

  • OutboxRouter: sendChunkedToAll() now builds a single multi-filter REQ message
  • RelayPool: closeOnAllRelays() reverted to simple (no chunk subId scanning needed)
  • SubscriptionManager: EOSE matching reverted to exact subId match

Net result: -13 lines. Simpler code, fewer subscriptions.

Testing

  • Follow 500+ accounts → verify NO "too many concurrent REQs" errors
  • Verify NO "total filter items too large" errors (individual filters still ≤200)
  • Feed loads normally with all relays connected

The previous chunking approach created separate subscriptions per chunk
(feed, feed:c1, feed:c2), multiplying the subscription count per relay.
Relays with a 10-20 concurrent subscription limit rejected excess REQs
with 'too many concurrent REQs'.

Now packs all author chunks as multiple filters within a single REQ:
  ["REQ","feed",{authors:[1..200]},{authors:[201..400]},{authors:[401..500]}]

This keeps one subscription ID per logical request while still keeping
each individual filter under 200 authors.

- OutboxRouter: sendChunkedToAll builds a single multi-filter REQ
- RelayPool: revert closeOnAllRelays to simple (no chunk subId scanning)
- SubscriptionManager: revert EOSE matching to exact subId match
@barrydeen barrydeen merged commit c2555b5 into main Feb 22, 2026
@barrydeen barrydeen deleted the fix/chunk-as-multi-filter-req branch March 4, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant