fix(rds): fail fast when the Docker daemon refuses the container create (#8581)

* fix(rds): fail fast when the Docker daemon refuses the container create
* fix(rds): keep a Docker timeout or throttling on create retryable
This commit is contained in:
Vinícius Ribeiro authored and GitHub committed 2026-11-16 10:41:59 -04:00
1 parent 293514ca86
commit a76c67f0c2
7 files changed
+207 -3

No files matched your search

@@ -343,7 +343,15 @@ public class ContainerLifecycleManager {
labels.put(CREATE_ATTEMPT_LABEL, createAttemptId);
createCmd.withLabels(labels);
String containerId = createWithConflictRecovery(createCmd, spec, createAttemptId);
String containerId;
try {
containerId = createWithConflictRecovery(createCmd, spec, createAttemptId);
} catch (DockerException e) {
if (ContainerRejectedException.isRejection(e)) {
throw new ContainerRejectedException(e);
}
throw e;
}
LOG.infov("Created container {0} (name={1}, not yet started)", containerId, spec.name());
return containerId;
}
@@ -0,0 +1,26 @@
package io.floci.aws.core.common.docker;
import com.github.dockerjava.api.exception.DockerException;
/**
* The Docker daemon refused to create a container with a client error, such as an authorization
* plugin denying a host config option. Repeating the same create gets the same answer, so a
* service reports it as a non-retryable error instead of {@code InternalFailure}.
*/
public class ContainerRejectedException extends RuntimeException {
public ContainerRejectedException(DockerException cause) {
super("Docker rejected the container create: " + cause.getMessage(), cause);
}
/**
* Whether the daemon answered a create with a client error that a retry would get again. A
* name conflict and a missing object keep their own types, since callers recover from or
* report them, and a timeout (408) or throttling (429) stays retryable.
*/
static boolean isRejection(DockerException e) {
int status = e.getHttpStatus();
return status >= 400 && status < 500
&& status != 404 && status != 408 && status != 409 && status != 429;
}
}
@@ -10,6 +10,7 @@ import io.floci.aws.core.common.AwsQueryResponse;
import io.floci.aws.core.common.AwsRegionFacts;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.XmlBuilder;
import io.floci.aws.core.common.docker.ContainerRejectedException;
import io.floci.aws.services.docdb.DocDbQueryHandler;
import io.floci.aws.services.neptune.NeptuneQueryHandler;
import io.floci.aws.services.rds.export.RdsExportTaskService;
@@ -232,6 +233,10 @@ public class RdsQueryHandler {
};
} catch (AwsException e) {
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus());
} catch (ContainerRejectedException e) {
// A 500 makes SDKs retry the same rejected create for minutes.
LOG.warnv("RDS {0} failed: {1}", action, e.getMessage());
return AwsQueryResponse.error("InsufficientDBInstanceCapacity", e.getMessage(), AwsNamespaces.RDS, 400);
} catch (Exception e) {
LOG.errorv(e, "Unexpected error in RDS {0}", action);
return AwsQueryResponse.error("InternalFailure",
@@ -10,6 +10,7 @@ import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.Pagination;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.ServiceCallAuthorizer;
import io.floci.aws.core.common.docker.ContainerRejectedException;
import io.floci.aws.core.common.docker.DockerHostResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
@@ -534,7 +535,7 @@ public class RedshiftService implements ManagedSecretRotator {
clusters.put(identifier, cluster);
}
clusters.flush();
throw new AwsException("InternalFailure", "Failed to start container: " + e.getMessage(), 500);
throw clusterStartFailure("Failed to start container: ", e);
}
clusters.put(identifier, cluster);
@@ -2711,7 +2712,7 @@ public class RedshiftService implements ManagedSecretRotator {
} catch (Exception e) {
rollbackSnapshotRestore(cluster, proxyPort);
emitClusterRestoreFailure(clusterIdentifier, snapshotIdentifier);
throw new AwsException("InternalFailure", "Failed to restore cluster from snapshot: " + e.getMessage(), 500);
throw clusterStartFailure("Failed to restore cluster from snapshot: ", e);
}
storeCluster(cluster);
@@ -4153,6 +4154,14 @@ public class RedshiftService implements ManagedSecretRotator {
private static final String CLUSTER_DB_NAME = "dev";
private static AwsException clusterStartFailure(String context, Exception e) {
if (e instanceof ContainerRejectedException) {
// A 500 makes SDKs retry the same rejected create for minutes.
return new AwsException("InsufficientClusterCapacity", e.getMessage(), 400);
}
return new AwsException("InternalFailure", context + e.getMessage(), 500);
}
private int allocateProxyPort() {
int base = config.services().redshift().proxyBasePort();
int max = config.services().redshift().proxyMaxPort();