Skip to content

Commit

Permalink
ensure storage port never conflicts with client port
Browse files Browse the repository at this point in the history
  • Loading branch information
octonato committed Apr 6, 2020
1 parent 717f7a4 commit 5e7186e
Showing 1 changed file with 10 additions and 2 deletions.
Expand Up @@ -10,7 +10,7 @@ import java.nio.channels.ServerSocketChannel
import java.nio.file.Files
import java.util.concurrent.TimeUnit

import scala.annotation.varargs
import scala.annotation.{ tailrec, varargs }
import scala.collection.immutable
import scala.concurrent.duration._
import scala.util.control.NonFatal
Expand Down Expand Up @@ -82,6 +82,14 @@ object CassandraLauncher {
port
}

@tailrec
private def freePort(usedPort: Int): Int = {
val port = freePort()
// bad luck? try again
if (port == usedPort) freePort(usedPort)
else port
}

/**
* Use this to locate classpath elements from the current classpath to add
* to the classpath of the launched Cassandra.
Expand Down Expand Up @@ -193,7 +201,7 @@ object CassandraLauncher {

val realHost = host.getOrElse("127.0.0.1")
val realPort = if (port == 0) randomPort else port
val storagePort = freePort()
val storagePort = freePort(realPort)
println(
s"Starting Cassandra on port client port: $realPort storage port $storagePort host $realHost java version ${System
.getProperty("java.runtime.version")}")
Expand Down

0 comments on commit 5e7186e

Please sign in to comment.