Bug 2290472 - oslo.service SignalHandler executes handlers in an undefined order
Summary: oslo.service SignalHandler executes handlers in an undefined order
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: python-oslo-service
Version: 17.1 (Wallaby)
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: z4
: 17.1
Assignee: mbollo
QA Contact: dabarzil
URL:
Whiteboard:
Depends On:
Blocks: 2290473
TreeView+ depends on / blocked
 
Reported: 2024-06-04 20:53 UTC by Terry Wilson
Modified: 2024-11-21 09:31 UTC (History)
3 users (show)

Fixed In Version: python-oslo-service-2.5.1-17.1.20240821203746.c1e3398.el8ost
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2024-11-21 09:31:24 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
OpenStack gerrit 911627 0 None MERGED Make signal handling order predictable 2024-08-26 19:20:43 UTC
Red Hat Issue Tracker OSP-32208 0 None None None 2024-06-04 20:54:24 UTC
Red Hat Product Errata RHBA-2024:9973 0 None None None 2024-11-21 09:31:27 UTC

Description Terry Wilson 2024-06-04 20:53:01 UTC
Description of problem:
Due to the unordered nature of sets, it is possible for signal handlers like _gracefull_shutdown() to run first and clear the _signal_handlers before other registered handlers have run.


Version-Release number of selected component (if applicable):
17.1.3

How reproducible:
Randomly reproducible with a service launched with ServiceLauncher-launched service that calls SignalHandler.add_handler()

Steps to Reproduce:

import eventlet; eventlet.monkey_patch()

import os
import signal
import sys
import time

from oslo_config import cfg
from oslo_service import service


def one(*args):
    print("one")


def two(*args):
    print("two")


def three(*args):
    print("three")


class MyService(service.Service):
    def start(self):
        sh = service.SignalHandler()
        sh.add_handler("SIGTERM", one)
        sh.add_handler("SIGTERM", two)
        sh.add_handler("SIGTERM", three)

    def wait(self):
        os.kill(os.getpid(), signal.SIGTERM)


class MySL(service.ServiceLauncher):
    def _graceful_shutdown(self, *args, **kwargs):
        print("graceful")
        res = super()._graceful_shutdown(*args, **kwargs)
        return res


s = MyService()
l = MySL(cfg.CONF)
l.launch_service(s)
l.wait()




Actual results:
Signals are executed in an undefined order.

Expected results:
Signals are executed in a defined order, LIFO. (three, two, one, graceful)

Additional info:

Comment 1 Hervé Beraud 2024-06-07 07:27:52 UTC
Thanks for the heads up, I think it is worth backporting your patch (https://review.opendev.org/c/openstack/oslo.service/+/911627) to stable branches.

Comment 2 Hervé Beraud 2024-06-07 09:37:45 UTC
Assigning this BZ to Daniel who is our upstream Oslo release liaison.
Daniel (mbollo) is be able to backport (upstream and downstream) and Daniel is granted to release this fix.
I'm not anymore the release liaison of Oslo so I'm not anymore granted to propose releases for Oslo.

Comment 14 errata-xmlrpc 2024-11-21 09:31:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (RHOSP 17.1.4 bug fix and enhancement advisory), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2024:9973


Note You need to log in before you can comment on or make changes to this bug.