-
Notifications
You must be signed in to change notification settings - Fork 24
Add configurable max ports per device limit via -maxports flag #199
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
Add configurable max ports per device limit via -maxports flag #199
Conversation
Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com>
Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com>
Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com>
|
@copilot Let's change the logic a little bit so that when specifying |
Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com>
dad47c6
into
hansr/squash-port-openclose-storms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| if activePorts+inProgressAttempts < 10 { | ||
| // Total should not exceed MaxPortsPerDevice (active + in-progress) | ||
| // If maxPorts is 0, it means unlimited | ||
| if maxPorts == 0 || activePorts+inProgressAttempts < maxPorts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Inconsistent handling of negative maxports values blocks connections
The two rate limiting checks handle negative maxPorts values inconsistently. In socks.go, the condition maxPorts > 0 treats negative values as unlimited (skips rate limiting). However, in datapool.go, the condition maxPorts == 0 only matches exactly zero, so negative values fall through to activePorts+inProgressAttempts < maxPorts, which is always false when maxPorts is negative (since non-negative counts are never less than a negative number). This blocks all connection attempts when a negative value is passed. The datapool.go condition should use maxPorts <= 0 instead of maxPorts == 0 for consistency.
Additional Locations (1)
* fix port connection storms * more port open madness * ignore repeats * Add configurable max ports per device limit via -maxports flag (#199) * Initial plan * Extract hardcoded threshold of 10 into command line flag Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com> * Refactor: Extract fallback logic into GetMaxPortsPerDevice helper Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com> * Optimize: Cache GetMaxPortsPerDevice calls for performance Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com> * Change -maxports=0 to mean unlimited instead of using default Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com> --------- Co-authored-by: hansr <hansrempel@gmail.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: dominicletz <2987674+dominicletz@users.noreply.github.com>
The hardcoded limit of 10 concurrent ports per device was insufficient for gateway deployments handling hundreds of simultaneous requests to domains like
ddriveupdate.diode.link.Changes
-maxportsflag tosocksd,gateway, andpublishcommands (default: 10)Config.GetMaxPortsPerDevice()helper methoddatapool.IncrementConnectionAttempt()andsocks.doConnectDevice()to use configurable value-maxports=0disables rate limiting entirely (unlimited connections)Usage
This allows operators to tune the limit based on deployment characteristics while maintaining safe defaults for typical use cases. Setting the value to 0 removes all rate limiting for high-traffic gateway deployments.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Note
Adds a configurable per-device concurrent port limit via
-maxports(0=unlimited) and uses it for connection rate limiting in SOCKS/datapool; flags added togateway,publish, andsocksd.cfg.MaxPortsPerDeviceandConfig.GetMaxPortsPerDevice()inconfig/flag.go.-maxportsflag (default10,0= unlimited) incmd/diode/gateway.go,cmd/diode/publish.go, andcmd/diode/socksd.go.rpc/datapool.goIncrementConnectionAttempt()to enforceMaxPortsPerDeviceacross active and in-progress connections; prefetch config before lock.rpc/socks.godoConnectDevice()to skip candidates when active ports reachMaxPortsPerDevice(cached config read outside loop).Written by Cursor Bugbot for commit 594261c. This will update automatically on new commits. Configure here.