-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix 3 bugs responsible for a goroutine leak (plus one other bug) #7491
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
00de344
fix: close resolve channel before returning it
Stebalien 5f19f3b
fix: cancel resolve search context
Stebalien 84341d0
fix: use the correct context when resolving dnsaddr links
Stebalien 0f3bc65
fix: return results from resolve once
Stebalien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,16 +86,19 @@ func (ns *mpns) Resolve(ctx context.Context, name string, options ...opts.Resolv | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could someone carefully check the changes I made here. I think they're right, but this is tricky code. |
||
|
||
func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result { | ||
res := make(chan Result, 1) | ||
if strings.HasPrefix(name, "/ipfs/") { | ||
p, err := path.ParsePath(name) | ||
res := make(chan Result, 1) | ||
res <- Result{p, err} | ||
close(res) | ||
return res | ||
} | ||
|
||
if !strings.HasPrefix(name, "/") { | ||
p, err := path.ParsePath("/ipfs/" + name) | ||
res := make(chan Result, 1) | ||
res <- Result{p, err} | ||
close(res) | ||
return res | ||
} | ||
|
||
|
@@ -120,15 +123,12 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. | |
key := segments[2] | ||
|
||
if p, ok := ns.cacheGet(key); ok { | ||
var err error | ||
if len(segments) > 3 { | ||
var err error | ||
p, err = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3]) | ||
if err != nil { | ||
emitOnceResult(ctx, out, onceResult{value: p, err: err}) | ||
} | ||
} | ||
|
||
out <- onceResult{value: p} | ||
out <- onceResult{value: p, err: err} | ||
close(out) | ||
return out | ||
} | ||
|
@@ -180,17 +180,15 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. | |
best = res | ||
} | ||
p := res.value | ||
err := res.err | ||
ttl := res.ttl | ||
|
||
// Attach rest of the path | ||
if len(segments) > 3 { | ||
var err error | ||
p, err = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3]) | ||
if err != nil { | ||
emitOnceResult(ctx, out, onceResult{value: p, ttl: res.ttl, err: err}) | ||
} | ||
} | ||
|
||
emitOnceResult(ctx, out, onceResult{value: p, ttl: res.ttl, err: res.err}) | ||
emitOnceResult(ctx, out, onceResult{value: p, ttl: ttl, err: err}) | ||
case <-ctx.Done(): | ||
return | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really do anything. Was the intent here more a sanity check? It might mask errors in api.Search which is either a good or bad thing depending on how you look at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that we bail early from calling
api.Search
without reading the last result. We could say "search shouldn't return anything after the first error" but we don't currently make that guarantee.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k, makes sense. Is the fact that api.Search, or really the implementations of ResolveAsync, don't abort when they hit an error a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure. I started digging into this and hit a ton of other bugs here. I'm hoping we can merge ipfs/interface-go-ipfs-core#62, then fix the other issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm