Skip to content

"Invalid argument: setsockopt" in log when running as Windows service, JDK >8, IPv6 stack not present #372

Description

@justparking

When running as Windows service which has no IPv6 addressing, I've seen this in the log:

11-24 14:38:30.77 [org.nodel.discovery.NodelDiscoverer.172_16_90_20] 
Socket operation failed; this may occur during network topology transitions. 
Will retry / reinit regardless... 
msg:Invalid argument: setsockopt

This doesn't seem to happen with JDK 8, but I've seen it with 17 and 21.

And it does not happen when you run as a user.

Workaround:
Instruct the JVM to explicitly ignore IPv6 altogether using the JVM option -Djava.net.preferIPv4Stack=true

Service config looks like this:
Image

(you should just need to Stop and Start service)

From my research, this can be fixed using an alternative way to initialise the network interface:

Quick brain dump plus AI hinted, as what part of NodelDiscoverer.java might look like.

MulticastSocket socket = new MulticastSocket(0);

// Find the Network Interface
NetworkInterface ni = NetworkInterface.getByInetAddress(_intf);
if (ni == null || !ni.supportsMulticast())
    // pre-checks should have already avoided this but just in-case
    throw new IOException("Interface not found or does not support multicast: " + _intf);

// This is the line that works reliably under Windows services
socket.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);
// or: socket.setNetworkInterface(ni);

socket.setSoTimeout(5 * 60000);
socket.setReuseAddress(true);
socket.setTimeToLive(TTL);

socket.joinGroup(new InetSocketAddress(Discovery.MDNS_GROUP, 5353), ni);
// (the two-parameter joinGroup is preferred on Windows anyway)

NetworkInterface ni = NetworkInterface.getByInetAddress(_intf);
socket.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);

Metadata

Metadata

Assignees

Labels

bugSomething isn't working as expectedinconvenienceA minor inconvenience, not blockingworkaround existsA workaround is available for this issue

Type

Fields

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions