Skip to content

Commit

Permalink
fix: Remove resource offers in DealNegotiating[0] state on disconnect (
Browse files Browse the repository at this point in the history
…#475)

* fix: Remove resource offers in DealNegotiating[0] state

We remove resource offers in a unmatched DealNegotiating[0] state to
avoid matching them when their resource provider is not connected.

* chore: Rename remove offer method
  • Loading branch information
bgins authored Jan 6, 2025
1 parent 6b880ec commit 77b86af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions pkg/solver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,24 @@ func (controller *SolverController) addResourceOffer(resourceOffer data.Resource
return ret, nil
}

func (controller *SolverController) removeResourceOfferByResourceProvider(ID string) error {
controller.log.Info("remove resource offer", ID)
// Remove resource offers in an unmatched DealNegotiating[0] state
func (controller *SolverController) removeUnmatchedResourceOffers(resourceProviderID string) error {
controller.log.Info("remove resource offer", resourceProviderID)
resourceOffers, err := controller.store.GetResourceOffers(store.GetResourceOffersQuery{
ResourceProvider: ID,
ResourceProvider: resourceProviderID,
})
if err != nil {
return err
}

if len(resourceOffers) == 0 {
return nil
}

err = controller.store.RemoveResourceOffer(resourceOffers[0].ID)
if err != nil {
return err
for _, offer := range resourceOffers {
if offer.State == 0 {
err = controller.store.RemoveResourceOffer(offer.ID)
if err != nil {
controller.log.Error("remove resource offer failed",
fmt.Errorf("resource provider: %s, offer ID: %s, error: %s", resourceProviderID, offer.ID, err))
}
}
}

controller.writeEvent(SolverEvent{
Expand Down
2 changes: 1 addition & 1 deletion pkg/solver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (solverServer *solverServer) disconnectCB(connParams http.WSConnectionParam
CountryCode: connParams.CountryCode,
IP: connParams.IP,
})
solverServer.controller.removeResourceOfferByResourceProvider(connParams.ID)
solverServer.controller.removeUnmatchedResourceOffers(connParams.ID)
}
}

Expand Down

0 comments on commit 77b86af

Please sign in to comment.