Skip to content
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(discovery): findCtx is canceled too early by defer #2180

Merged

Conversation

walldiss
Copy link
Member

@walldiss walldiss commented May 9, 2023

Overview

If underlying discovery.FindPeers closes the channel, discover call would return calling the defer stack and canceling fincCtx too early. This would result in all routines trying to establish connection being canceled before having time to succeed. Fixed by changing defer stack order of wg.Wait and context.Cancel calls.

The change also fixes flaky get_peer_from_discovery test, since flakiness was actually a bug.

@walldiss walldiss added area:shares Shares and samples kind:fix Attached to bug-fixing PRs labels May 9, 2023
@walldiss walldiss requested a review from renaynay as a code owner May 9, 2023 18:17
@walldiss walldiss self-assigned this May 9, 2023
Wondertan
Wondertan previously approved these changes May 9, 2023
Copy link
Member

@Wondertan Wondertan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's comment that the order matters.

@renaynay renaynay changed the title fix(discovery): finxCtx is canceled too early by defer fix(discovery): findCtx is canceled too early by defer May 10, 2023
renaynay
renaynay previously approved these changes May 10, 2023
Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just group the defer statements into a

defer func() { 
 wg.Wait()
 findCancel()
}()

so the ordering of exec is explicitly clear.

alternatively make comment but i think if the ordering matters that much, it's better to make explicitly obvious

@walldiss walldiss dismissed stale reviews from renaynay and Wondertan via f94cb4f May 10, 2023 08:58
@codecov-commenter
Copy link

Codecov Report

Merging #2180 (5d22111) into main (7f556f0) will decrease coverage by 0.22%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2180      +/-   ##
==========================================
- Coverage   56.04%   55.83%   -0.22%     
==========================================
  Files         215      215              
  Lines       13918    13922       +4     
==========================================
- Hits         7800     7773      -27     
- Misses       5340     5367      +27     
- Partials      778      782       +4     
Impacted Files Coverage Δ
share/availability/discovery/discovery.go 73.21% <100.00%> (-2.92%) ⬇️

... and 4 files with indirect coverage changes

@Wondertan
Copy link
Member

The order of exec is clear and deterministic with defer as well, but I don't mind grouping them in one defer

@walldiss walldiss merged commit ddf2f93 into celestiaorg:main May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:shares Shares and samples kind:fix Attached to bug-fixing PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants