Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
fix: give one minute timeouts to function calls instead of block retr…
Browse files Browse the repository at this point in the history
…ievals to get around issues with shared IPLD ADL contexts
  • Loading branch information
aschmahmann committed Sep 14, 2021
1 parent ca1fe7e commit d0512ce
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid.
// create a selector to traverse and match all path segments
pathSelector := pathAllSelector(p[:len(p)-1])

// create a new cancellable session
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

// resolve node before last path segment
nodes, lastCid, depth, err := r.resolveNodes(ctx, c, pathSelector)
if err != nil {
Expand Down Expand Up @@ -132,6 +136,10 @@ func (r *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Node,
// create a selector to traverse all path segments but only match the last
pathSelector := pathLeafSelector(p)

// create a new cancellable session
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

nodes, c, _, err := r.resolveNodes(ctx, c, pathSelector)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -172,6 +180,10 @@ func (r *Resolver) ResolvePathComponents(ctx context.Context, fpath path.Path) (
// create a selector to traverse and match all path segments
pathSelector := pathAllSelector(p)

// create a new cancellable session
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

nodes, _, _, err := r.resolveNodes(ctx, c, pathSelector)
if err != nil {
evt.Append(logging.LoggableMap{"error": err.Error()})
Expand Down Expand Up @@ -218,10 +230,6 @@ func (r *Resolver) ResolveLinks(ctx context.Context, ndd ipld.Node, names []stri
// Finds nodes matching the selector starting with a cid. Returns the matched nodes, the cid of the block containing
// the last node, and the depth of the last node within its block (root is depth 0).
func (r *Resolver) resolveNodes(ctx context.Context, c cid.Cid, sel ipld.Node) ([]ipld.Node, cid.Cid, int, error) {
// create a new cancellable session
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

session := r.FetcherFactory.NewSession(ctx)

// traverse selector
Expand Down

0 comments on commit d0512ce

Please sign in to comment.