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
10 changes: 2 additions & 8 deletions server/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ func FreeTCPAddr() (addr, port string, err error) {
return "", "", err
}

closer := func() {
err := l.Close()
if err != nil {
// TODO: Handle with #870
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.

}

defer closer()

portI := l.Addr().(*net.TCPAddr).Port
port = fmt.Sprintf("%d", portI)
addr = fmt.Sprintf("tcp://0.0.0.0:%s", port)
Expand Down