From baa2261a4599213097b6780dd001ad1b6205d344 Mon Sep 17 00:00:00 2001 From: Davin Shearer <2205472+scholarsmate@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:21:22 -0400 Subject: [PATCH 1/2] Update scala from 2.13.12 to 2.13.13 --- server/scala/build.sbt | 2 +- server/scala/project/plugins.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/scala/build.sbt b/server/scala/build.sbt index 3942bf533..7d151ddc0 100644 --- a/server/scala/build.sbt +++ b/server/scala/build.sbt @@ -59,7 +59,7 @@ lazy val enumeratumVersion = "1.7.2" lazy val commonSettings = Seq( organization := "com.ctc", - scalaVersion := "2.13.12", + scalaVersion := "2.13.13", version := omegaEditVersion, organizationName := "Concurrent Technologies Corporation", maintainer := "oss@ctc.com", diff --git a/server/scala/project/plugins.sbt b/server/scala/project/plugins.sbt index 50536e3e4..718a8b1b9 100644 --- a/server/scala/project/plugins.sbt +++ b/server/scala/project/plugins.sbt @@ -22,6 +22,6 @@ addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.5") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.1") addSbtPlugin("org.apache.pekko" % "pekko-grpc-sbt-plugin" % "1.0.0") addSbtPlugin("org.musigma" % "sbt-rat" % "0.7.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.0") addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.2.2") From c5886b0c551b312999f40268553fd07815753758 Mon Sep 17 00:00:00 2001 From: Davin Shearer <2205472+scholarsmate@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:21:22 -0400 Subject: [PATCH 2/2] Update scala from 2.13.12 to 2.13.13 --- packages/client/src/server.ts | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/client/src/server.ts b/packages/client/src/server.ts index c5533b7da..bc10c4ed4 100644 --- a/packages/client/src/server.ts +++ b/packages/client/src/server.ts @@ -54,6 +54,47 @@ export function delay(milliseconds: number): Promise { }) } +/** + * Find the first available port in a range, or null if no ports are available + * @param startPort start of the port range + * @param endPort end of the port range + * @returns first available port in the range, or null if no ports are available + */ +export async function findFirstAvailablePort( + startPort: number, + endPort: number +): Promise { + const log = getLogger() + return new Promise((resolve) => { + let currentPort = startPort + + const tryNextPort = () => { + if (currentPort > endPort) { + resolve(null) // No ports available in the range + return + } + + const server = createServer() + server.listen(currentPort, '0.0.0.0', () => { + server.close((err) => { + if (err) { + log.error(`Error closing server on port ${currentPort}: ${err}`) + } + resolve(currentPort) // Found an available port + }) + }) + + server.on('error', (err) => { + log.error(`Error when trying to listen on port ${currentPort}: ${err}`) + ++currentPort + tryNextPort() // Try the next port + }) + } + + tryNextPort() + }) +} + /** * Wait for file to exist * @param filePath path to file to wait for