From ebe2a9ee114fc32273e07d8052bed08b1d9b101b Mon Sep 17 00:00:00 2001 From: Jimmy Liu Jia <91264074+JimmyLiuJia@users.noreply.github.com> Date: Sun, 1 Nov 2026 21:14:22 +0800 Subject: [PATCH] fix(rds): release cluster proxy port after failed container start (#7196) --- .../floci/services/rds/RdsService.java | 26 ++++++++++++------- .../floci/services/rds/RdsServiceTest.java | 8 +++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java index 960b1f7798..7a6b96cf5a 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java @@ -5063,15 +5063,23 @@ public class RdsService implements Resettable, ResourceProvider { cluster.setStorageEncrypted(storageEncrypted); cluster.setContainerStorageResourceId(clusterResourceId); if (!mock) { - String image = imageForEngine(engine, engineVersion); - String clusterVolumeId = String.format("%06x", new SecureRandom().nextInt(0xFFFFFF)); - String clusterDockerVolumeName = newVolumeName( - clusterVolumeId, clusterResourceId); - RdsContainerHandle handle = containerManager.tryStart( - clusterArn, id, clusterResourceId, clusterDockerVolumeName, - engine, image, - masterUsername, masterPassword, databaseName, - clusterEngineParameters(currentAccountId(), effectiveRegion, paramGroupName)); + String clusterVolumeId; + String clusterDockerVolumeName; + RdsContainerHandle handle; + try { + String image = imageForEngine(engine, engineVersion); + clusterVolumeId = String.format("%06x", new SecureRandom().nextInt(0xFFFFFF)); + clusterDockerVolumeName = newVolumeName( + clusterVolumeId, clusterResourceId); + handle = containerManager.tryStart( + clusterArn, id, clusterResourceId, clusterDockerVolumeName, + engine, image, + masterUsername, masterPassword, databaseName, + clusterEngineParameters(currentAccountId(), effectiveRegion, paramGroupName)); + } catch (RuntimeException | Error e) { + releaseProxyPort(proxyPort); + throw e; + } if (handle != null) { cluster.setContainerId(handle.getContainerId()); cluster.setContainerHost(handle.getHost()); diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java index 96b6438ff6..0ae1013ab4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java @@ -1631,9 +1631,10 @@ class RdsServiceTest { } } - /** A failed create must release the identifier so a clean retry can proceed. */ + /** A failed container start must release its identifier and reserved port for retry. */ @Test void createDbClusterFailureReleasesTheIdentifierForRetry() { + when(rdsConfig.proxyMaxPort()).thenReturn(7000); when(containerManager.tryStart(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) .thenThrow(new RuntimeException("image pull failed")) .thenReturn(new RdsContainerHandle("cont-id", "id", "localhost", 5432)); @@ -1642,8 +1643,9 @@ class RdsServiceTest { rdsService.createDbCluster("retry-cluster", "postgres", "17.5", "admin", "password", "dbname", false, null, null, null, false)); - assertNotNull(rdsService.createDbCluster("retry-cluster", "postgres", "17.5", - "admin", "password", "dbname", false, null, null, null, false)); + DbCluster retried = rdsService.createDbCluster("retry-cluster", "postgres", "17.5", + "admin", "password", "dbname", false, null, null, null, false); + assertEquals(7000, retried.getProxyPort()); verify(containerManager, times(2)).tryStart(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); }