NETWORKING: Fix Portability of SO_LINGER=0 in Tests (#33895)

* Setting SO_LINGER for open but not connected non-blocking sockets
throws on OSX
  * Fixed by only applying setting to connected sockets which will save
the same number of FDs as doing it on open sockets anyway
* closes #33879
This commit is contained in:
Armin Braun 2018-09-21 10:08:16 +02:00 committed by GitHub
parent 5f7f793f43
commit 3a5b8a71b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -277,8 +277,9 @@ public class MockNioTransport extends TcpTransport {
@Override @Override
public void setSoLinger(int value) throws IOException { public void setSoLinger(int value) throws IOException {
if (isOpen()) { SocketChannel rawChannel = getRawChannel();
getRawChannel().setOption(StandardSocketOptions.SO_LINGER, value); if (rawChannel.isConnected()) {
rawChannel.setOption(StandardSocketOptions.SO_LINGER, value);
} }
} }

View File

@ -19,7 +19,6 @@
package org.elasticsearch.transport.nio; package org.elasticsearch.transport.nio;
import org.apache.lucene.util.Constants;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@ -100,7 +99,6 @@ public class SimpleMockNioTransportTests extends AbstractSimpleTransportTestCase
} }
public void testConnectException() throws UnknownHostException { public void testConnectException() throws UnknownHostException {
assumeFalse("Broken on Darwin - https://github.com/elastic/elasticsearch/issues/33879", Constants.MAC_OS_X);
try { try {
serviceA.connectToNode(new DiscoveryNode("C", new TransportAddress(InetAddress.getByName("localhost"), 9876), serviceA.connectToNode(new DiscoveryNode("C", new TransportAddress(InetAddress.getByName("localhost"), 9876),
emptyMap(), emptySet(),Version.CURRENT)); emptyMap(), emptySet(),Version.CURRENT));