-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,12 @@ | |
return nil | ||
} | ||
|
||
defer unlocker.Unlock() | ||
shouldUnlock := true | ||
defer func() { | ||
if shouldUnlock { | ||
unlocker.Unlock() | ||
} | ||
}() | ||
|
||
_, err = r.db.GetQuoteRequestByID(ctx, req.TransactionId) | ||
// expect no results | ||
|
@@ -120,12 +125,17 @@ | |
if err != nil { | ||
return fmt.Errorf("could not get quote request handler: %w", err) | ||
} | ||
// Forward instead of lock since we called lock above. | ||
fwdErr := qr.Forward(ctx, dbReq) | ||
if fwdErr != nil { | ||
logger.Errorf("could not forward to handle seen: %w", fwdErr) | ||
span.AddEvent("could not forward to handle seen") | ||
} | ||
|
||
// 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())) | ||
} | ||
}() | ||
Comment on lines
+128
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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()))
}
}() |
||
|
||
return nil | ||
} | ||
|
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 withfmt.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:
📝 Committable suggestion