From 758638cabb68c0b715a13410b4635720a38e0324 Mon Sep 17 00:00:00 2001 From: "Maxim.Kolmakov" Date: Fri, 12 Jul 2024 12:17:01 +0200 Subject: [PATCH] [starter][event bus] Retry on the same port GitOrigin-RevId: 0537784e4cd9cb25bc5718c63bb3744b14cfb746 --- .../bus/shared/client/LocalEventBusServerClient.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/performanceTesting/event-bus/src/com/intellij/tools/ide/starter/bus/shared/client/LocalEventBusServerClient.kt b/plugins/performanceTesting/event-bus/src/com/intellij/tools/ide/starter/bus/shared/client/LocalEventBusServerClient.kt index 9cd228f62e4c..09a9595adc6d 100644 --- a/plugins/performanceTesting/event-bus/src/com/intellij/tools/ide/starter/bus/shared/client/LocalEventBusServerClient.kt +++ b/plugins/performanceTesting/event-bus/src/com/intellij/tools/ide/starter/bus/shared/client/LocalEventBusServerClient.kt @@ -32,13 +32,12 @@ class LocalEventBusServerClient(val server: LocalEventBusServer) : EventBusServe return sendRequest("GET", endpoint, requestBody) } - private fun sendRequest(method: String, endpoint: String, requestBody: String?): String { + private fun sendRequest(method: String, endpoint: String, requestBody: String?, retriesOnTheSamePort: Int = 0): String { val url = URL("http://localhost:${server.port}/$endpoint") val connection = url.openConnection() as HttpURLConnection return try { connection.requestMethod = method - connection.connectTimeout = 3000 // 3 seconds - connection.readTimeout = 10000 // 10 seconds + connection.connectTimeout = 1000 // 1 seconds requestBody?.also { body -> connection.doOutput = true connection.setRequestProperty("Content-Type", "application/json") @@ -58,8 +57,12 @@ class LocalEventBusServerClient(val server: LocalEventBusServer) : EventBusServe } } catch (e: ConnectException) { - if (!server.updatePort()) throw e - sendRequest(method, endpoint, requestBody) + if (retriesOnTheSamePort < 3) { + sendRequest(method, endpoint, requestBody, retriesOnTheSamePort + 1) + } else { + if (!server.updatePort()) throw e + sendRequest(method, endpoint, requestBody, 0) + } } finally { connection.disconnect()