-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat(rfq-relayer): forward bridge requests in new goroutine #3276
Conversation
WalkthroughThe changes in this pull request primarily focus on the Changes
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
Documentation and Community
|
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: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- services/rfq/relayer/service/handlers.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
services/rfq/relayer/service/handlers.go (1)
50-55
: Properly manage lock unlocking with 'shouldUnlock' variableThe introduction of the
shouldUnlock
variable along with the deferred function ensures that the lock is only released when appropriate. This prevents premature unlocking and potential race conditions.
|
||
// Forward in new goroutine and retain the lock. | ||
shouldUnlock = false | ||
go func() { | ||
defer unlocker.Unlock() | ||
fwdErr := qr.Forward(ctx, dbReq) | ||
if fwdErr != nil { | ||
logger.Errorf("could not forward to handle seen: %w", fwdErr) | ||
span.AddEvent(fmt.Sprintf("could not forward to handle seen: %s", fwdErr.Error())) | ||
} | ||
}() |
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.
🛠️ Refactor suggestion
Avoid holding locks during asynchronous operations
Holding the lock while executing qr.Forward
in a new goroutine can lead to performance issues or deadlocks if the forwarded operation takes time or encounters errors. It's generally best to minimize the duration of held locks and avoid keeping them during long-running asynchronous tasks.
Consider releasing the lock before starting the goroutine or restructuring the code so that the lock is not held during the asynchronous operation. Here's a possible refactoring:
// Release the lock before forwarding
unlocker.Unlock()
go func() {
fwdErr := qr.Forward(ctx, dbReq)
if fwdErr != nil {
logger.Errorf("could not forward to handle seen: %v", fwdErr)
span.AddEvent(fmt.Sprintf("could not forward to handle seen: %s", fwdErr.Error()))
}
}()
defer unlocker.Unlock() | ||
fwdErr := qr.Forward(ctx, dbReq) | ||
if fwdErr != nil { | ||
logger.Errorf("could not forward to handle seen: %w", fwdErr) |
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.
Correct format specifier in logger message
The format specifier %w
is used with fmt.Errorf
for error wrapping and may not be supported by the logger, resulting in incorrect error messages. Instead, use %v
or %s
to properly format the error.
Apply this diff to fix the format specifier:
-logger.Errorf("could not forward to handle seen: %w", fwdErr)
+logger.Errorf("could not forward to handle seen: %v", fwdErr)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
logger.Errorf("could not forward to handle seen: %w", fwdErr) | |
logger.Errorf("could not forward to handle seen: %v", fwdErr) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3276 +/- ##
============================================
Coverage ? 24.99618%
============================================
Files ? 198
Lines ? 13074
Branches ? 82
============================================
Hits ? 3268
Misses ? 9526
Partials ? 280
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Deploying sanguine-fe with Cloudflare Pages
|
Summary by CodeRabbit
Bug Fixes
Refactor