Skip to content

Commit

Permalink
feat(rfq-relayer): forward bridge requests in new goroutine (#3276)
Browse files Browse the repository at this point in the history
* Feat: call Forward in new goroutine in handleBridgeRequestedLog

* [goreleaser]
  • Loading branch information
dwasse authored Oct 11, 2024
1 parent bedbf2d commit 099624f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions services/rfq/relayer/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func (r *Relayer) handleBridgeRequestedLog(parentCtx context.Context, req *fastb
return nil
}

defer unlocker.Unlock()
shouldUnlock := true
defer func() {
if shouldUnlock {
unlocker.Unlock()
}
}()

_, err = r.db.GetQuoteRequestByID(ctx, req.TransactionId)
// expect no results
Expand Down Expand Up @@ -120,12 +125,17 @@ func (r *Relayer) handleBridgeRequestedLog(parentCtx context.Context, req *fastb
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()))
}
}()

return nil
}
Expand Down

0 comments on commit 099624f

Please sign in to comment.