Class neutron.common.utils.Timer is not thread safe

Bug #1832925 reported by Rodolfo Alonso
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Won't Fix
Medium
Rodolfo Alonso

Bug Description

In "Timer" the method used to control the timeout of the class context is not thread safe. If two different threads running in the same process set signal.signal, the last one will prevail in favor of the first one:

  signal.signal(signal.SIGALRM, self._timeout_handler)
  signal.alarm(self._timeout)

Another method, thread safe, to control the class timeout should be implemented.

This error can be seen in [1].

[1] http://logs.openstack.org/89/664889/4/check/openstack-tox-py37/ecb7c8d/testr_results.html.gz

Miguel Lavalle (minsel)
Changed in neutron:
status: New → Confirmed
importance: Undecided → Medium
Changed in neutron:
assignee: nobody → Rodolfo Alonso (rodolfo-alonso-hernandez)
tags: added: gate-failure unittest
Revision history for this message
Nate Johnston (nate-johnston) wrote :

Would it be possible to use threading.Timer to implement the timer instead?

Revision history for this message
Slawek Kaplonski (slaweq) wrote :

@Rodolfo: wasn't this already fixed?

Revision history for this message
Rodolfo Alonso (rodolfo-alonso-hernandez) wrote :

Hi @Slawek:

Not really. You can't use this context inside a thread because "signal" won't work. "Only main thread is allowed to set a signal handler": https://docs.python.org/3.4/library/signal.html#signals-and-threads

So I think we can close this bug and warn any developer using this context not in the main thread.

I can document this in the class doc string.

Regards.

Revision history for this message
Slawek Kaplonski (slaweq) wrote :

@Rodolfo, so if You can, please propose simple patch with additional docstring and we will be able to close this one :)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to neutron (master)

Related fix proposed to branch: master
Review: https://review.opendev.org/714100

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to neutron (master)

Reviewed: https://review.opendev.org/714100
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=79af9e786d6feb19b8f282f0c69afa1516c4b929
Submitter: Zuul
Branch: master

commit 79af9e786d6feb19b8f282f0c69afa1516c4b929
Author: Rodolfo Alonso Hernandez <email address hidden>
Date: Fri Mar 20 12:20:44 2020 +0000

    Add usage note in utils.Timer class

    This class, when a timeout is defined, cannot be used in other
    than the main thread. When a timeout is defined, an alarm signal is
    set. Only the main thread is allowed to set a signal handler and the
    signal handlers are always executed in this main thread [1].

    [1] https://docs.python.org/3/library/signal.html#signals-and-threads

    Change-Id: I9ffdde96873fa3a557e4a4ddeeb9abdf89d3045a
    Related-Bug: #1832925

Revision history for this message
Slawek Kaplonski (slaweq) wrote :

Closing this according to the Rodolfo's comment above and docs patch which is already merged.

Changed in neutron:
status: Confirmed → Fix Released
status: Fix Released → Won't Fix
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.