Improve tunnel_sync server side rpc to handle race conditions

Bug #1426427 reported by Romil Gupta
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
neutron
Expired
Medium
Unassigned

Bug Description

We have a concern that we may have race conditions with the following code snippet:

            if host:
                host_endpoint = driver.obj.get_endpoint_by_host(host)
                ip_endpoint = driver.obj.get_endpoint_by_ip(tunnel_ip)

                if (ip_endpoint and ip_endpoint.host is None
                    and host_endpoint is None):
                    driver.obj.delete_endpoint(ip_endpoint.ip_address)
                elif (ip_endpoint and ip_endpoint.host != host):
                    msg = (_("Tunnel IP %(ip)s in use with host %(host)s"),
                           {'ip': ip_endpoint.ip_address,
                            'host': ip_endpoint.host})
                    raise exc.InvalidInput(error_message=msg)
                elif (host_endpoint and host_endpoint.ip_address != tunnel_ip):
                    # Notify all other listening agents to delete stale tunnels
                    self._notifier.tunnel_delete(rpc_context,
                        host_endpoint.ip_address, tunnel_type)
                    driver.obj.delete_endpoint(host_endpoint.ip_address)

Consider two threads (A and B), where for

Thread A we have following use case:
if Host is passed from an agent and it is not found in DB but the passed tunnel_ip is found, delete the endpoint from DB and add the endpoint with
(tunnel_ip, host), it's an upgrade case.

whereas for Thread B we have following use case:
if passed host and tunnel_ip are not found in the DB, it is a new endpoint.

Both threads will do the following in the end:

            tunnel = driver.obj.add_endpoint(tunnel_ip, host)
            tunnels = driver.obj.get_endpoints()
            entry = {'tunnels': tunnels}
            # Notify all other listening agents
            self._notifier.tunnel_update(rpc_context, tunnel.ip_address,
                                         tunnel_type)
            # Return the list of tunnels IP's to the agent
            return entry

Since, Thread A first deletes the endpoints and adds it, we may have chances where Thread B doesn't get that endpoint in get_endpoints call during race condition.

One way to overcome this problem would be instead of doing delete_endpoint we could introduce update_endpoint method in type_drivers.

Tags: ml2
Romil Gupta (romilg)
Changed in neutron:
status: New → Incomplete
Romil Gupta (romilg)
Changed in neutron:
status: Incomplete → Invalid
Romil Gupta (romilg)
summary: - Improve tunnel_sync server side rpc
+ Improve tunnel_sync server side rpc to handle race conditions
Romil Gupta (romilg)
description: updated
Changed in neutron:
assignee: nobody → Romil Gupta (romilg)
status: Invalid → New
tags: added: ml2
Changed in neutron:
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.openstack.org/189686

Changed in neutron:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron (master)

Change abandoned by Armando Migliaccio (<email address hidden>) on branch: master
Review: https://review.openstack.org/189686
Reason: This review is > 4 weeks without comment, and failed Jenkins the last time it was checked. We are abandoning this for now. Feel free to reactivate the review by pressing the restore button and leaving a 'recheck' comment to get fresh test results.

Changed in neutron:
status: In Progress → Incomplete
assignee: Romil Gupta (romilg) → nobody
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for neutron because there has been no activity for 60 days.]

Changed in neutron:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.