Skip to content

Commit e6979c6

Browse files
committed
SCBC-495: cluster.disconnect() is intermittently not blocking until all components are ended
The root cause here was that disconnect was shutting down a threadpool, and accidentally doing that work on a thread that was itself on the same threadpool. Change-Id: I3c95df82cc23f346799032dba6596af4e0ecaa51 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/234779 Reviewed-by: David Nault <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 10719d6 commit e6979c6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

scala-client/src/main/scala-2/com/couchbase/client/scala/AsyncCluster.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,14 @@ class AsyncCluster(
308308
def disconnect(timeout: Duration = env.timeoutConfig.disconnectTimeout()): Future[Unit] = {
309309
FutureConversions
310310
.javaMonoToScalaFuture(couchbaseOps.shutdown(timeout))
311-
.map(_ => if (env.owned) env.shutdown(timeout))
311+
.flatMap(_ =>
312+
if (env.owned) {
313+
// Explicitly put this on the global threadpool, otherwise it will execute on the
314+
// threadpool we are shutting down due to the implicit `ec` in scope.
315+
Future(env.shutdown(timeout))(scala.concurrent.ExecutionContext.global)
316+
} else
317+
Future.successful(())
318+
)
312319
}
313320

314321
/** Returns a `DiagnosticsResult`, reflecting the SDK's current view of all its existing connections to the

scala-client/src/test/scala/com/couchbase/client/scala/EnvironmentSpec.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.couchbase.client.scala
22

33
import com.couchbase.client.core.env.WanDevelopmentProfile
44
import com.couchbase.client.scala.env._
5-
import org.junit.jupiter.api.Test
5+
import org.junit.jupiter.api.{RepeatedTest, Test}
66

77
import scala.concurrent.duration.{Duration, _}
88
import scala.util.{Success, Try}
@@ -144,7 +144,8 @@ class EnvironmentSpec {
144144
}
145145
}
146146

147-
@Test
147+
// Repeated as this has been an intermittent failure in the past
148+
@RepeatedTest(10)
148149
def closeOwnedEnvironment(): Unit = {
149150
val clusterTry: Try[Cluster] = Cluster.connect("1.2.3.4", "username", "password")
150151

0 commit comments

Comments
 (0)