Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[daemon_base] fix to not reregister signal handler #4998

Merged

Conversation

vdahiya12
Copy link
Contributor

@vdahiya12 vdahiya12 commented Jul 17, 2020

  • Why I did it
    Currently all daemons inherit from daemon_base class, and for
    signal handling functionality they register the signal_handler() by
    overriding the siganl_handler() in daemon_base by their own
    implmentation.
    But some sonic_platform instances also can invoke the daemon_base
    constructor while trying to instantiate the common utilities
    for example
    platform_chassis = sonic_platform.platform.Platform().get_chassis()
    This will cause the re registration of signal_handler which will
    cause base class signal_handler() to be invoked when the daemon
    gets a signal, whereas their own signal_handler should have been
    invoked.

  • How I did it
    We only register the siganl_handler once, and if signal_handler has
    been registered, not re register it.

  • How to verify it
    Run any daemon and send a signal to it and ensure that the
    correct signal_handler is invoked.

-src/sonic-daemon-base/sonic_daemon_base/daemon_base.py
added an if check for signal registration to not re register if
the signal is already registered.

Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com

-src/sonic-daemon-base/sonic_daemon_base/daemon_base.py
Problem:
Currently all daemons inherit from daemon_base class, and for
signal handling functionality they register the signal_handler() by
overriding the siganl_handler() in daemon_base by their own
implmentation.
But some sonic_platform instances also can invoke the daemon_base
constructor while trying to instantiate the common utilities
for example
platform_chassis = sonic_platform.platform.Platform().get_chassis()
This will cause the re registration of signal_handler which will
cause base class signal_handler() to be invoked when the daemon
gets a signal, whereas their own signal_handler should have been
invoked.

Fix:
We only register the siganl_handler once, and if signal_handler has
been registered, not re register it.

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
added a coment for the changes

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
fixing some spellings

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@jleveque
Copy link
Contributor

Retest vsimage please

1 similar comment
@jleveque
Copy link
Contributor

Retest vsimage please

@jleveque
Copy link
Contributor

Just a note for posterity: only Python-based daemons should inherit from the DaemonBase class or even import daemon_base.py. However, currently, other Python code is using this module, like the platform API, which in turn has created the situation which is being fixed by this PR.

I have intended to create a Python library that both DaemonBase as well as non-daemon code can import which contains common, general SONiC-related functions. I have opened an issue to track this: #4999

@lguohan
Copy link
Collaborator

lguohan commented Jul 18, 2020

retest vsimage please

@vdahiya12 vdahiya12 merged commit c9983df into sonic-net:master Jul 20, 2020
abdosi pushed a commit that referenced this pull request Jul 26, 2020
* [daemon_base] fix to not reregister signal handler

-src/sonic-daemon-base/sonic_daemon_base/daemon_base.py
Problem:
Currently all daemons inherit from daemon_base class, and for
signal handling functionality they register the signal_handler() by
overriding the siganl_handler() in daemon_base by their own
implmentation.
But some sonic_platform instances also can invoke the daemon_base
constructor while trying to instantiate the common utilities
for example
platform_chassis = sonic_platform.platform.Platform().get_chassis()
This will cause the re registration of signal_handler which will
cause base class signal_handler() to be invoked when the daemon
gets a signal, whereas their own signal_handler should have been
invoked.

Fix:
We only register the siganl_handler once, and if signal_handler has
been registered, not re register it.

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>

* [daemon_base] fix to not reregister signal handler

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants