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

Support SO_REUSEADDR #1195

Closed
ry opened this issue Nov 15, 2018 · 8 comments
Closed

Support SO_REUSEADDR #1195

ry opened this issue Nov 15, 2018 · 8 comments
Labels
feat new feature (which has been agreed to/accepted) good first issue Good for newcomers

Comments

@ry
Copy link
Member

ry commented Nov 15, 2018

Because of the lack of this, many networking tests resort to using different ports.

@ry
Copy link
Member Author

ry commented Feb 24, 2020

Feb 24, 2020: Still an issue that we want to solve.

@ry ry added the feat new feature (which has been agreed to/accepted) label Feb 24, 2020
@jsouto18
Copy link
Contributor

jsouto18 commented Mar 5, 2020

@ry as soon as I'm done with UDS I'll take care of this one!

@bartlomieju
Copy link
Member

To implement this feature, net2 crate should be added to dependencies and reuse_address method should be called before creating a socket.

@attila-lin
Copy link
Contributor

Is it still be an issue? Can I take it?

@bartlomieju bartlomieju added the good first issue Good for newcomers label Jan 31, 2022
@bartlomieju
Copy link
Member

Marking as good first issue. For example how to implement this see #13103

@Trolloldem
Copy link
Contributor

Trolloldem commented Feb 27, 2022

@bartlomieju I tried to add the requested feature. I decided to not use net2 as suggested, since the library is now deprecated.
In order to achieve the same functionality I used the socket2 crate, which is already a dependency listed in ext/net/Cargo.toml.

For now I have a working unit test for op_net_listen, now I have to adapt the changes for the TLS version.
In order to achieve retro compatibility, the proposed method is composed as follows:

const listener1 = Deno.listen({ hostname: "127.0.0.1", port: 3500, reuseAddress: true});
const listener2 = Deno.listen({ hostname: "192.168.1.7", port: 3500, reuseAddress: true});

where the reuseAddress field is optional and defaults to false.

I should be able to open a PR in the following days. But first I have a question:

  • in this is issue is mentioned that support for SO_REUSEADDR is needed
  • this options allows the use case in which the same host has two different ip (127.0.0.1 and 192.168.1.7 for example)
  • the exposed use case shows that without this feature it is necessary to use different ports
  • I think that it in order to fully achieve the wanted result it is necessary to support the SO_REUSEPORT option
  • in this way it is possible to support the following code:
const listener1 = Deno.listen({ hostname: "127.0.0.1", port: 3500, reusePort: true});
const listener2 = Deno.listen({ hostname: "127.0.0.1", port: 3500, reusePort: true});

where the reusePort field is optional and defaults to false.

Let me know if you think that these changes could be interesting and if it is the case to open a PR to add them.

@bartlomieju
Copy link
Member

@Trolloldem thanks for looking into this. What you described sounds good to me and the proposed API looks good. socket2 is indeed preferable in this case.

It might be hard to test these properly, but please open a PR first and let's work from there.

@lucacasonato
Copy link
Member

We specify SO_REUSEADDR on all sockets by default, just like Node.js and Go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants