Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Limit calls to subscribe() #1197

Merged
merged 4 commits into from
Jul 31, 2023
Merged

Conversation

adityapk00
Copy link
Contributor

@adityapk00 adityapk00 commented Jul 29, 2023

Motivation

The subscribe() RPC is a long-lived one, which causes excessive resource consumption for every open connection. Limit these to 4 per IP and 4096 total per Node.

Change Summary

  • Limit subscribe() to 4 per IP
  • Limit 4096 total
  • Tests

Merge Checklist

Choose all relevant options below by adding an x now or at any time before submitting for review


PR-Codex overview

This PR focuses on limiting the number of simultaneous subscribe() streams by IP address in the Hubble app.

Detailed summary

  • Added extractIPAddress function to extract the IP part from "ip:port"
  • Modified checkNodeAddrs function to check the IP address to bind to and the combined IP, transport, and port multiaddr
  • Added SUBSCRIBE_PERIP_LIMIT and SUBSCRIBE_GLOBAL_LIMIT constants in server.ts
  • Added IpConnectionLimiter class to limit the number of simultaneous connections by IP address
  • Modified Server class to use IpConnectionLimiter for rate limiting in subscribe method
  • Added clearRateLimiters method in Server class to clear rate limiters
  • Updated tests in eventService.test.ts and server.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2023

🦋 Changeset detected

Latest commit: c5cc599

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@farcaster/hubble Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hub-monorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2023 0:51am

@codecov
Copy link

codecov bot commented Jul 29, 2023

Codecov Report

Patch coverage: 75.47% and project coverage change: -0.07% ⚠️

Comparison is base (eae1ba8) 69.38% compared to head (c5cc599) 69.31%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1197      +/-   ##
==========================================
- Coverage   69.38%   69.31%   -0.07%     
==========================================
  Files          84       84              
  Lines        7428     7473      +45     
  Branches     1604     1614      +10     
==========================================
+ Hits         5154     5180      +26     
- Misses       2123     2141      +18     
- Partials      151      152       +1     
Files Changed Coverage Δ
apps/hubble/src/utils/p2p.ts 63.52% <71.42%> (+0.70%) ⬆️
apps/hubble/src/rpc/server.ts 74.47% <76.08%> (-1.19%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adityapk00 adityapk00 merged commit a1b9ace into farcasterxyz:main Jul 31, 2023
@adityapk00 adityapk00 deleted the limitsubs branch July 31, 2023 13:58
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