-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Network: Allow to listen on virtual interfaces. #19568
Conversation
Previously when trying to listen on virtual interfaces during bootstrap the application would stop working - the interface couldn't be found by the NetworkUtils class. The NetworkUtils utilize the underlying JDK NetworkInterface class which, when asked to lookup by name only takes physical interfaces into account, failing at virtual (or subinterfaces) ones (returning null). Note that when interating over all interfaces, both physical and virtual ones are taken into account. This changeset asks for all known interfaces, iterates over them and matches on the given name as part of the loop, allowing it to catch both physical and virtual interfaces. As a result, elasticsearch can now also serve on virtual interfaces. A test case has been added which makes sure that all iterable interfaces can be found by their respective name. Note that this PR is a second iteration over the previously merged but later reverted elastic#19537 because it causes tests to fail when interfaces are down. The test has been modified to take this into account now. Closes elastic#17473 Relates elastic#19537
Can one of the admins verify this patch? |
@rmuir @jasontedor here's the updated PR with the test case being more restrictive to avoid failures on downed interfaces (and to that regard interfaces with no addresses assigned to them, since this is another case where the elastic code throws an exception) |
@@ -227,7 +227,14 @@ public static boolean defaultReuseAddress() { | |||
|
|||
/** Returns addresses for the given interface (it must be marked up) */ | |||
static InetAddress[] getAddressesForInterface(String name) throws SocketException { | |||
NetworkInterface intf = NetworkInterface.getByName(name); | |||
NetworkInterface intf = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldnt a stream using getInterfaces().stream().filter().findFirst()
be nicer here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I didn't realize the codebase was on java 8 - good idea!
Just a quick note: I'm out the next two weeks so I can either fix it up when I'm back or feel free to amend and push if you want to get it in early :) |
@spinscale are there any other changes (other than the stream() conversion) that I should make in the next batch? |
Previously when trying to listen on virtual interfaces during bootstrap the application would stop working - the interface couldn't be found by the NetworkUtils class. The NetworkUtils utilize the underlying JDK NetworkInterface class which, when asked to lookup by name only takes physical interfaces into account, failing at virtual (or subinterfaces) ones (returning null). Note that when interating over all interfaces, both physical and virtual ones are taken into account. This changeset asks for all known interfaces, iterates over them and matches on the given name as part of the loop, allowing it to catch both physical and virtual interfaces. As a result, elasticsearch can now also serve on virtual interfaces. A test case has been added which makes sure that all iterable interfaces can be found by their respective name. Note that this PR is a second iteration over the previously merged but later reverted elastic#19537 because it causes tests to fail when interfaces are down. The test has been modified to take this into account now. Closes elastic#17473 Closes elastic#19568 Relates elastic#19537
Previously when trying to listen on virtual interfaces during bootstrap the application would stop working - the interface couldn't be found by the NetworkUtils class. The NetworkUtils utilize the underlying JDK NetworkInterface class which, when asked to lookup by name only takes physical interfaces into account, failing at virtual (or subinterfaces) ones (returning null). Note that when interating over all interfaces, both physical and virtual ones are taken into account. This changeset asks for all known interfaces, iterates over them and matches on the given name as part of the loop, allowing it to catch both physical and virtual interfaces. As a result, elasticsearch can now also serve on virtual interfaces. A test case has been added which makes sure that all iterable interfaces can be found by their respective name. Note that this PR is a second iteration over the previously merged but later reverted #19537 because it causes tests to fail when interfaces are down. The test has been modified to take this into account now. Closes #17473 Closes #19568 Relates #19537
Previously when trying to listen on virtual interfaces during bootstrap the application would stop working - the interface couldn't be found by the NetworkUtils class. The NetworkUtils utilize the underlying JDK NetworkInterface class which, when asked to lookup by name only takes physical interfaces into account, failing at virtual (or subinterfaces) ones (returning null). Note that when interating over all interfaces, both physical and virtual ones are taken into account. This changeset asks for all known interfaces, iterates over them and matches on the given name as part of the loop, allowing it to catch both physical and virtual interfaces. As a result, elasticsearch can now also serve on virtual interfaces. A test case has been added which makes sure that all iterable interfaces can be found by their respective name. Note that this PR is a second iteration over the previously merged but later reverted #19537 because it causes tests to fail when interfaces are down. The test has been modified to take this into account now. Closes #17473 Closes #19568 Relates #19537
👍 |
Previously when trying to listen on virtual interfaces during
bootstrap the application would stop working - the interface
couldn't be found by the NetworkUtils class.
The NetworkUtils utilize the underlying JDK NetworkInterface
class which, when asked to lookup by name only takes physical
interfaces into account, failing at virtual (or subinterfaces)
ones (returning null).
Note that when interating over all interfaces, both physical and
virtual ones are taken into account.
This changeset asks for all known interfaces, iterates over them
and matches on the given name as part of the loop, allowing it
to catch both physical and virtual interfaces.
As a result, elasticsearch can now also serve on virtual
interfaces.
A test case has been added which makes sure that all
iterable interfaces can be found by their respective name.
Note that this PR is a second iteration over the previously
merged but later reverted #19537 because it causes tests
to fail when interfaces are down. The test has been modified
to take this into account now.
Closes #17473
Relates #19537