fix(ec2): retain firewall identity during container teardown (#6492)

Capture the primary ENI before asynchronous termination can race with service-side interface release. Cover unregister after the interface list is cleared at the removal boundary.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-25 08:07:27 -04:00
1 parent bab7af3a21
commit 73fc6fd0c1
2 files changed
+41 -3

No files matched your search

@@ -1337,12 +1337,15 @@ public class Ec2ContainerManager {
String containerId;
String containerIp;
String imdsSourceIp;
String firewallEniId;
int sshHostPort;
synchronized (instance) {
containerId = instance.getDockerContainerId();
containerIp = instance.getContainerBridgeIp();
imdsSourceIp = instance.getImdsSourceIp();
sshHostPort = instance.getSshHostPort();
firewallEniId = instance.getNetworkInterfaces() == null || instance.getNetworkInterfaces().isEmpty()
? null : instance.getNetworkInterfaces().getFirst().getNetworkInterfaceId();
instance.setState(InstanceState.shuttingDown());
}
executor.submit(() -> {
@@ -1371,9 +1374,8 @@ public class Ec2ContainerManager {
Thread.currentThread().interrupt();
}
}
if (firewallManager != null && firewallManager.enabled()
&& instance.getNetworkInterfaces() != null && !instance.getNetworkInterfaces().isEmpty()) {
firewallManager.unregister(instance.getNetworkInterfaces().getFirst().getNetworkInterfaceId());
if (firewallManager != null && firewallManager.enabled() && firewallEniId != null) {
firewallManager.unregister(firewallEniId);
}
if (sshHostPort > 0) {
portAllocator.release(sshHostPort);