mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): release cluster proxy port after failed container start (#7196)
This commit is contained in:
1 parent
a54ca5e0c9
commit
ebe2a9ee11
2 files changed
+22
-12
No files matched your search
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user