Skip to content

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

Merged
mergify[bot] merged 7 commits intomasterfrom
alessio/FreeTCPAddr-various-fixes
Mar 15, 2021
Merged

server: try avoid the "address already in use" error#8842
mergify[bot] merged 7 commits intomasterfrom
alessio/FreeTCPAddr-various-fixes

Conversation

@alessio
Copy link
Copy Markdown
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
@alessio alessio requested review from gsora and odeke-em March 10, 2021 14:37
@codecov
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown

orijbot commented Mar 13, 2021

@orijbot
Copy link
Copy Markdown

orijbot commented Mar 14, 2021

@orijbot
Copy link
Copy Markdown

orijbot commented Mar 14, 2021

Copy link
Copy Markdown
Contributor

@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
Copy Markdown

orijbot commented Mar 15, 2021

@orijbot
Copy link
Copy Markdown

orijbot commented Mar 15, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants