diff --git a/storagenode/orders/store.go b/storagenode/orders/store.go index ec25fb4b8..e224eb5b1 100644 --- a/storagenode/orders/store.go +++ b/storagenode/orders/store.go @@ -102,6 +102,11 @@ func (store *FileStore) BeginEnqueue(satelliteID storj.NodeID, createdAt time.Ti // always remove the in flight operation defer store.enqueueFinishedLocked(satelliteID, createdAt) + // caller wants to abort; free file for sending and return with no error + if info == nil { + return nil + } + // check that the info matches what the enqueue was begun with if info.Limit.SatelliteId != satelliteID || !info.Limit.OrderCreation.Equal(createdAt) { return OrderError.New("invalid info passed in to enqueue commit") diff --git a/storagenode/piecestore/endpoint.go b/storagenode/piecestore/endpoint.go index 2880a61c4..f34367d8e 100644 --- a/storagenode/piecestore/endpoint.go +++ b/storagenode/piecestore/endpoint.go @@ -660,12 +660,20 @@ func (endpoint *Endpoint) beginSaveOrder(limit *pb.OrderLimit) (_commit func(ctx done := false return func(ctx context.Context, order *pb.Order) { - // TODO: do this in a goroutine - if order == nil || order.Amount <= 0 || done { + if done { return } done = true + if order == nil || order.Amount <= 0 { + // free unsent orders file for sending without writing anything + err = commit(nil) + if err != nil { + endpoint.log.Error("failed to unlock orders file", zap.Error(err)) + } + return + } + err = commit(&orders.Info{Limit: limit, Order: order}) if err != nil { endpoint.log.Error("failed to add order", zap.Error(err))