-
-
Notifications
You must be signed in to change notification settings - Fork 278
feat(backoff): implement secure jitter using crypto/rand #1882
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
Conversation
WalkthroughThis pull request involves a version update from v1.2.4 to v1.2.5 across multiple files in the Permify project. The changes primarily focus on updating version numbers in documentation and internal version tracking files. Additionally, there's a notable enhancement in the PostgreSQL storage utility, where random number generation has been improved by switching to a more secure cryptographic random number generation method. Changes
Sequence DiagramsequenceDiagram
participant Code as Source Code
participant Rand as crypto/rand
participant Util as WaitWithBackoff
Code->>Util: Call with retry parameters
Util->>Rand: Generate secure random float
Rand-->>Util: Return cryptographically secure random value
Util->>Util: Calculate jittered backoff
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
internal/storage/postgres/utils/common.go (2)
166-170: Optional enhancement: include more context in logs.
Consider adding the retry attempt number and maximum backoff thresholds to the log statements for improved observability.
178-185: Consider improved error handling insecureRandomFloat64.
Currently, it returns 0 on read failure, which might cause repeated immediate retries with minimal jitter. Logging or retrying therand.Readcall could provide better visibility or resilience.func secureRandomFloat64() float64 { var b [8]byte if _, err := rand.Read(b[:]); err != nil { - return 0 // Default to 0 jitter on error + slog.Error("Failed to generate secure random bytes", slog.String("error", err.Error())) + return 0 } return float64(binary.BigEndian.Uint64(b[:])) / (1 << 64) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pkg/pb/base/v1/openapi.pb.gois excluded by!**/*.pb.go
📒 Files selected for processing (5)
docs/api-reference/apidocs.swagger.json(1 hunks)docs/api-reference/openapiv2/apidocs.swagger.json(1 hunks)internal/info.go(1 hunks)internal/storage/postgres/utils/common.go(2 hunks)proto/base/v1/openapi.proto(1 hunks)
✅ Files skipped from review due to trivial changes (4)
- internal/info.go
- docs/api-reference/apidocs.swagger.json
- docs/api-reference/openapiv2/apidocs.swagger.json
- proto/base/v1/openapi.proto
🔇 Additional comments (5)
internal/storage/postgres/utils/common.go (5)
5-6: Use ofcrypto/randis more secure thanmath/rand.
This change ensures cryptographically secure random number generation, mitigating predictability in backoff jitter.
159-161: Base backoff calculation is appropriate.
Using exponential growth limited to 1 second is a standard approach for controlling reconnection or retry storms.
162-165: Great use of jitter for backoff.
Jitter helps avoid synchronized retries across multiple clients, reducing load spikes.
171-171: Context cancellation check is correct.
Terminating early if the context is done prevents unnecessary waits.
177-177: Maintain a concise code layout.
This blank line is a minor formatting choice, but everything looks fine. No action needed.
Summary by CodeRabbit
Documentation
Chores
Security