Skip to content

Commit

Permalink
fix(share/availability): propagate errors from light availability pro…
Browse files Browse the repository at this point in the history
…perly (#3888)
  • Loading branch information
walldiss authored Oct 29, 2024
1 parent f5d9d3a commit c913b13
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 c913b13

Please sign in to comment.