Skip to content

Commit 2558943

Browse files
author
Gabriel Monroy
committed
Merge pull request #422 from opdemand/fix-delete-ec2-sg
Fixed #355 -- retry deleting EC2 security group.
2 parents 044a9b5 + 95d750f commit 2558943

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

provider/ec2.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ def destroy_layer(layer):
8787
conn.delete_key_pair(name)
8888
# there's an ec2 race condition on instances terminating
8989
# successfully but still holding a lock on the security group
90-
# let's take a nap
91-
time.sleep(5)
92-
try:
93-
conn.delete_security_group(name)
94-
except EC2ResponseError as e:
95-
if e.code != 'InvalidGroup.NotFound':
96-
raise e
90+
for i in range(5):
91+
# let's take a nap
92+
time.sleep(i ** 1.25) # 1, 2.4, 3.9, 5.6, 7.4
93+
try:
94+
conn.delete_security_group(name)
95+
return
96+
except EC2ResponseError as err:
97+
if err.code == 'InvalidGroup.NotFound':
98+
return
99+
elif err.code in ('InvalidGroup.InUse',
100+
'DependencyViolation') and i < 4:
101+
continue # retry
102+
else:
103+
raise
97104

98105

99106
def build_node(node):

0 commit comments

Comments
 (0)