Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions iib/workers/tasks/opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def inner(*args, **kwargs):
port_purposes=port_purposes_updated,
)

def unlock_active_lock(active_locks):
for active_lock in active_locks:
active_lock.unlock()

# Use the function to retrieve values from the generator
while not lock_success:
new_locks = port_file_lock_generator.get_new_locks()
Expand All @@ -278,14 +282,19 @@ def inner(*args, **kwargs):
# Exception raised during execution of func()
except AddressAlreadyInUse:
lock_success = False
for active_lock in currently_active_locks:
active_lock.unlock()
unlock_active_lock(currently_active_locks)

except Exception:
lock_success = False
# Exception raised we should remove locks.
unlock_active_lock(currently_active_locks)
# re-raise exception
raise

finally:
# Exit loop after successful lock acquisition
if lock_success:
for active_lock in currently_active_locks:
active_lock.unlock()
unlock_active_lock(currently_active_locks)
break

return result
Expand Down