Bug 2290472

Summary: oslo.service SignalHandler executes handlers in an undefined order
Product: Red Hat OpenStack Reporter: Terry Wilson <twilson>
Component: python-oslo-serviceAssignee: mbollo
Status: CLOSED ERRATA QA Contact: dabarzil
Severity: high Docs Contact:
Priority: high    
Version: 17.1 (Wallaby)CC: jlibosva, lmiccini, mariel
Target Milestone: z4Keywords: Triaged
Target Release: 17.1   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-oslo-service-2.5.1-17.1.20240821203746.c1e3398.el8ost Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-11-21 09:31:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2290473    

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