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

Set SO_REUSEADDR for all socket channels to avoid bind errors #82

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

nethraravindran
Copy link
Contributor

@nethraravindran nethraravindran commented Aug 29, 2018

Motivation:
To allow reuse socket address and port.

Previously swift-nio was overriding ChannelOptions.socket ie. allowing only one socket option to set.

Hence as a work-around we were always reusing the port based on the value of allowPortReuse

With this fix apple/swift-nio#597 , swift-nio allows to set two distinct ChannelOptions.socket of one type.

And so we can have both the options ChannelOptions.socket set for the server

.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: 1)
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)

With this we reuse the port only when necessary.

Package.swift Outdated
@@ -28,7 +28,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-nio.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", .branch("master")),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a temporary change until we have swift-nio 1.9.3

Package.swift Outdated
@@ -28,7 +28,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-nio.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", .branch("master")),
Copy link
Contributor

Choose a reason for hiding this comment

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

1.9.3 is out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ianpartridge Thanks! I'm changing it now

@nethraravindran nethraravindran changed the title Set ChannelOptions.socket to reuse port and address Set SO_REUSEADDR for all socket channels to avoid bind errors Aug 29, 2018
@nethraravindran
Copy link
Contributor Author

Copy link
Contributor

@pushkarnk pushkarnk left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants