Skip to content

Commit f589e60

Browse files
dnaultbsideup
authored andcommitted
Fix java.net.SocketException exception in CouchbaseContainer.stop() (#859)
Motivation ========== When stop() was called without a prior call to createCouchbaseEnvironment(), it would throw a SocketException because stopCluster() would end up trying to initialize the cluster at the same time the container is being shut down. Modifications ============= Call stopCluster() before stopping the container, instead of in parallel. Result ====== stopCluster() might still call createCouchbaseEnvironment(), but the call succeeds and the environment is immediately cleaned up.
1 parent b5564a5 commit f589e60

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public List<Integer> getBoundPortNumbers() {
180180

181181
@Override
182182
public void stop() {
183-
Stream.<Runnable>of(super::stop, proxy::stop, this::stopCluster).parallel().forEach(Runnable::run);
183+
stopCluster();
184+
Stream.<Runnable>of(super::stop, proxy::stop).parallel().forEach(Runnable::run);
184185
}
185186

186187
private void stopCluster() {

modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ public void shouldUseCorrectDockerImage() {
1212
Assert.assertEquals(CouchbaseContainer.DOCKER_IMAGE_NAME + CouchbaseContainer.VERSION,
1313
couchbaseContainer.getDockerImageName());
1414
}
15+
16+
@Test
17+
public void shouldStopWithoutThrowingException() {
18+
CouchbaseContainer couchbaseContainer = new CouchbaseContainer();
19+
couchbaseContainer.start();
20+
couchbaseContainer.stop();
21+
}
1522
}

0 commit comments

Comments
 (0)