Skip to content

Commit

Permalink
MessagingServiceTest listenOptionalSecureConnection and listenRequire…
Browse files Browse the repository at this point in the history
…dSecureConnection fail sporadically

patch by David Capwell; reviewed by Benedict Elliott Smith, Caleb Rackliffe for CASSANDRA-17033
  • Loading branch information
dcapwell committed Nov 9, 2021
1 parent 599294c commit 59aab69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
21 changes: 17 additions & 4 deletions src/java/org/apache/cassandra/net/InboundSockets.java
Expand Up @@ -99,15 +99,28 @@ private Future<Void> open(Consumer<ChannelPipeline> pipelineInjector)
throw new IllegalStateException();
binding = InboundConnectionInitiator.bind(settings, connections, pipelineInjector);
}

return binding.addListener(ignore -> {
// isOpen is defined as "listen.isOpen", but this is set AFTER the binding future is set
// to make sure the future returned does not complete until listen is set, need a new
// future to replicate "Future.map" behavior.
AsyncChannelPromise promise = new AsyncChannelPromise(binding.channel());
binding.addListener(f -> {
if (!f.isSuccess())
{
synchronized (this)
{
binding = null;
}
promise.setFailure(f.cause());
return;
}
synchronized (this)
{
if (binding.isSuccess())
listen = binding.channel();
listen = binding.channel();
binding = null;
}
promise.setSuccess(null);
});
return promise;
}

/**
Expand Down
13 changes: 8 additions & 5 deletions test/unit/org/apache/cassandra/net/MessagingServiceTest.java
Expand Up @@ -310,9 +310,12 @@ public void listenRequiredSecureConnectionWithBroadcastAddrAndLegacyPort() throw
@Test
public void listenOptionalSecureConnection() throws InterruptedException
{
ServerEncryptionOptions serverEncryptionOptions = new ServerEncryptionOptions()
.withOptional(true);
listen(serverEncryptionOptions, false);
for (int i = 0; i < 500; i++) // test used to be flaky, so run in a loop to make sure stable (see CASSANDRA-17033)
{
ServerEncryptionOptions serverEncryptionOptions = new ServerEncryptionOptions()
.withOptional(true);
listen(serverEncryptionOptions, false);
}
}

@Test
Expand All @@ -339,8 +342,8 @@ private void listen(ServerEncryptionOptions serverEncryptionOptions, boolean lis
InboundSockets connections = new InboundSockets(settings);
try
{
connections.open().await();
Assert.assertTrue(connections.isListening());
connections.open().sync();
Assert.assertTrue("connections is not listening", connections.isListening());

Set<InetAddressAndPort> expect = new HashSet<>();
expect.add(InetAddressAndPort.getByAddressOverrideDefaults(listenAddress, DatabaseDescriptor.getStoragePort()));
Expand Down

0 comments on commit 59aab69

Please sign in to comment.