ethersphere / swarm

Swarm: Censorship resistant storage and communication infrastructure for a truly sovereign digital society
https://swarm.ethereum.org/
GNU Lesser General Public License v3.0
488 stars 110 forks source link

lookup timeout on feed content recovery #2210

Open santicomp2014 opened 4 years ago

santicomp2014 commented 4 years ago

In #2202 the timeout for getFeedContent was removed.

There seems to be an issue with the context that is passed down to the feed operations.

If there is a context timeout (starting from the download) that expires before reaching getFeedContent, then the recovery process will fail.

The combination of timeouts (the one from the download + the one from the recovery) is complex and should be tested appropriately to determine if the feed is able to get the content in time.

// getFeedContent creates a feed with the given topic and user, and attempts to fetch its content using the given handler
func getFeedContent(ctx context.Context, handler feed.GenericHandler, topic feed.Topic, user common.Address) ([]byte, error) {
    fd := feed.Feed{
        Topic: topic,
        User:  user,
    }
    query := feed.NewQueryLatest(&fd, lookup.NoClue)
    //ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
        //defer cancel()

    _, err := handler.Lookup(ctx, query)
    // feed should still be queried even if there are no updates
    if err != nil && err.Error() != "no feed updates found" {
        return nil, ErrFeedLookup
    }

    _, content, err := handler.GetContent(&fd)
    if err != nil {
        return nil, ErrFeedContent
    }

    return content, nil
}