Skip to content

Commit 8a47577

Browse files
committed
Fix race condition in members batch update API call
Fix a potential race condition, the member batch update API call computes a delta between the current state of the members in the DB and the members in the requests. But it fetches the members from the DB before locking the load balancer, it means that another Octavia service may still update the list of members, then the computation of the changes may be incorrect. The list of members is now queried in the locked section. Closes-Bug: #2036156 Change-Id: I453ff385620f488a3e43d4fda01634cdce3be5d4
1 parent 0426285 commit 8a47577

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

octavia/api/v2/controllers/member.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ def put(self, additive_only=False, members_=None):
336336

337337
with context.session.begin():
338338
db_pool = self._get_db_pool(context.session, self.pool_id)
339-
old_members = db_pool.members
340339

341340
project_id, provider = self._get_lb_project_id_provider(
342341
context.session, db_pool.load_balancer_id)
@@ -354,6 +353,11 @@ def put(self, additive_only=False, members_=None):
354353
with context.session.begin():
355354
self._test_lb_and_listener_and_pool_statuses(context.session)
356355

356+
# Reload the pool, the members may have been updated between the
357+
# first query in this function and the lock of the loadbalancer
358+
db_pool = self._get_db_pool(context.session, self.pool_id)
359+
old_members = db_pool.members
360+
357361
old_member_uniques = {
358362
(m.ip_address, m.protocol_port): m.id for m in old_members}
359363
new_member_uniques = [
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a race condition in the members batch update API call, the data
5+
passed to the Octavia worker service may have been incorrect when quickly
6+
sending successive API calls. Then the load balancer was stuck in
7+
PENDING_UPDATE provisioning_status.

0 commit comments

Comments
 (0)