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

server: try avoid the "address already in use" error #8842

Merged
merged 7 commits into from
Mar 15, 2021

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Mar 10, 2021

Replace defer l.Close() with l.Close() to shutdown the listener
as fast as possible to avoid the "bind: address already in use"
error that so often occurs in CI build.

From: phayes/freeport#8
Reference: #6671


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Replace defer l.Close() with l.Close() to shutdown the listener
as fast as possible to avoid the "bind: address already in use"
error that so often occurs in CI build.

From: phayes/freeport#8
Reference: #6671
@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #8842 (7887dec) into master (c6af0ed) will increase coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8842   +/-   ##
=======================================
  Coverage   59.15%   59.15%           
=======================================
  Files         570      570           
  Lines       31770    31768    -2     
=======================================
  Hits        18793    18793           
+ Misses      10776    10774    -2     
  Partials     2201     2201           
Impacted Files Coverage Δ
server/test_helpers.go 0.00% <0.00%> (ø)

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

All tests seem to pass on CI, so I'm okay with this.

@amaury1093
Copy link
Contributor

@alessio https://github.com/cosmos/cosmos-sdk/pull/8842/checks?check_run_id=2078853719#step:6:139 😢

panic(err)
}
if err := l.Close(); err != nil {
return "", "", fmt.Errorf("couldn't close the listener: %w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we wrap it?

sdkerrors.Wrap(sdkerrors.ErrIO, ....)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure, good one. I'm not just yet sure this PR actually fixes anything at all. I warmly welcome suggestions - and I'm CC'ing @odeke-em too.

If this does not improve anything, I'd just close it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The PR has good improvement - it removes panic

Copy link
Contributor Author

@alessio alessio Mar 13, 2021

Choose a reason for hiding this comment

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

[thinking aloud]
shouldn't I call Close() as the very last statement of this function before returning?
[/thinking aloud]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, @robert-zaremba got a great point that we should wrap it, for consistency with other errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orijbot
Copy link

orijbot commented Mar 13, 2021

@alessio alessio added A:automerge Automatically merge PR once all prerequisites pass. and removed A:automerge Automatically merge PR once all prerequisites pass. labels Mar 14, 2021
@orijbot
Copy link

orijbot commented Mar 14, 2021

@orijbot
Copy link

orijbot commented Mar 14, 2021

@alessio alessio added the A:automerge Automatically merge PR once all prerequisites pass. label Mar 14, 2021
Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @alessio! Good start for now and thanks for referencing that issue that I flagged a while ago. Later on would be nice for us to dig into the syscall package and figure out the calls to get an available address and bind to it then pass in a listener to the code that needs it. Currently still closing is at the mercy of the OS reusing file descriptors at a speed. Thanks again, and my apologies for the late reply.

@mergify mergify bot merged commit d02a397 into master Mar 15, 2021
@mergify mergify bot deleted the alessio/FreeTCPAddr-various-fixes branch March 15, 2021 10:15
@orijbot
Copy link

orijbot commented Mar 15, 2021

@orijbot
Copy link

orijbot commented Mar 15, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants