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

protocol/mdns: Use SO_REUSEPORT for the mDNS socket #68

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

altonen
Copy link
Contributor

@altonen altonen commented Mar 28, 2024

On macOS, failure to use SO_REUSEPORT would result in mDNS not being able to bind to the socket, causing Litep2p::new() to exit with EADDRINUSE.

On macOS, failure to use `SO_REUSEPORT` would result in mDNS not being
able to bind to the socket, causing `Litep2p::new()` to exit with
`EADDRINUSE`.
Comment on lines +131 to +132
#[cfg(unix)]
socket.set_reuse_port(true)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

dq: What was the reason this was commented out in the past with a "todo: fix"? Did something break previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIR when I wrote the code, I was using an incorrect version of socket2 or something which caused compilation to fail on Linux even though I had #[cfg(unix)]. Since the code worked without port_reuse(true), I just commented the code out and was planning on revisiting it in the future but never did until now.

Copy link
Collaborator

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

LGTM! Just one question about the prior comment

@dmitry-markin
Copy link
Collaborator

On macOS, failure to use SO_REUSEPORT would result in mDNS not being able to bind to the socket, causing Litep2p::new() to exit with EADDRINUSE.

Is there an explanation for macOS behaving this way?

@altonen
Copy link
Contributor Author

altonen commented Mar 28, 2024

On macOS, failure to use SO_REUSEPORT would result in mDNS not being able to bind to the socket, causing Litep2p::new() to exit with EADDRINUSE.

Is there an explanation for macOS behaving this way?

This is the best reference I could find after a quick search. Looks like there are subtle differences between the operating systems which makes mDNS work on Linux despite not enabling SO_REUSEPORT

@dmitry-markin dmitry-markin merged commit 44b5910 into paritytech:master Mar 28, 2024
8 checks passed
@lexnv lexnv mentioned this pull request Apr 5, 2024
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