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

fix(userspace/falco): make termination and signal handlers more stable #2239

Merged
merged 7 commits into from
Oct 11, 2022

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind bug

/kind cleanup

Any specific area of the project related to this PR?

/area engine

What this PR does / why we need it:

Signal handlers are used in Falco to force termination, hot reload, or output reloading. However, the current implementation is not stable for neither thread-safety and async-signal safety (more here: https://docs.oracle.com/cd/E19455-01/806-5257/gen-26/index.html). This PR refactors the way signals are handled to make sure it's safe both on single-threaded (e.g. capturing only syscalls) and multi-threaded use cases (e.g. multiple event sources in parallel).

Accordingly, the event source termination stage has been refactored to be more stable by using atomic values to check 1) that the event source has actually finished processing events, and 2) that the corresponding thread has already been joined. This is safer than simply relying on the thread.joinable() and thread.join() primitives.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…able

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
@jasondellaluce
Copy link
Contributor Author

/milestone 0.33.0

@poiana poiana added this to the 0.33.0 milestone Oct 10, 2022
Comment on lines +87 to +90
if(! create_handler(SIGINT, ::terminate_signal_handler, ret) ||
! create_handler(SIGTERM, ::terminate_signal_handler, ret) ||
! create_handler(SIGUSR1, ::reopen_outputs_signal_handler, ret) ||
! create_handler(SIGHUP, ::restart_signal_handler, ret))
Copy link
Member

@Andreagit97 Andreagit97 Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about something like:

Suggested change
if(! create_handler(SIGINT, ::terminate_signal_handler, ret) ||
! create_handler(SIGTERM, ::terminate_signal_handler, ret) ||
! create_handler(SIGUSR1, ::reopen_outputs_signal_handler, ret) ||
! create_handler(SIGHUP, ::restart_signal_handler, ret))
return !create_handler(SIGINT, ::terminate_signal_handler, ret) ||
!create_handler(SIGTERM, ::terminate_signal_handler, ret) ||
!create_handler(SIGUSR1, ::reopen_outputs_signal_handler, ret) ||
!create_handler(SIGHUP, ::restart_signal_handler, ret)) ? run_result::fatal("") : run_result::ok();

Or if we don't want to return fatal just run_result::ok() in both cases 🤔 just a nitpick feel free to ignore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_handler already sets its own error results in the passed-in ret, so errors are already catched.

… times

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…ailures

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Oct 11, 2022

LGTM label has been added.

Git tree hash: 9c46687de8ccdb55ef0497400ebf1d701f2787ec

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Oct 11, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, jasondellaluce

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 5f2bc6a into master Oct 11, 2022
@poiana poiana deleted the fix/signals-termination branch October 11, 2022 17:23
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.

4 participants