Skip to content

Commit

Permalink
propagate errors in light sampling properly
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Oct 28, 2024
1 parent 08ca0ed commit 74df5af
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions share/availability/light/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package light
import (
"context"
"errors"
"fmt"
"sync"

"github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -123,19 +124,19 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header
}
wg.Wait()

if errors.Is(ctx.Err(), context.Canceled) {
// Availability did not complete due to context cancellation, return context error instead of
// share.ErrNotAvailable
return ctx.Err()
}

// store the result of the sampling session
bs := encodeSamples(failedSamples)
la.dsLk.Lock()
err = la.ds.Put(ctx, key, bs)
la.dsLk.Unlock()
if err != nil {
log.Errorw("Failed to store sampling result", "error", err)
return fmt.Errorf("failed to store sampling result: %w", err)
}

if errors.Is(ctx.Err(), context.Canceled) {
// Availability did not complete due to context cancellation, return context error instead of
// share.ErrNotAvailable
return ctx.Err()
}

// if any of the samples failed, return an error
Expand Down

0 comments on commit 74df5af

Please sign in to comment.