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

refactor(libsinsp): use smart pointer for m_resolver in sinsp_dns_manager #1558

Merged
merged 4 commits into from
Dec 12, 2023

Conversation

incertum
Copy link
Contributor

@incertum incertum commented Dec 7, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

Follow up #1526 (comment).
It seems that we need to keep using a pointer, but a smart pointer now as you can't otherwise truly check if std::thread is empty.

CC @FedeDP @federico-sysdig @LucaGuerra

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@incertum
Copy link
Contributor Author

incertum commented Dec 7, 2023

CI Build / build-shared-libs-linux-amd64 🧐 (pull_request)

appears to have some tbb linkage issues.

Copy link
Contributor

@federico-sysdig federico-sysdig left a comment

Choose a reason for hiding this comment

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

It seems that we need to keep using a pointer, but a smart pointer now as you can't otherwise truly check if std::thread is empty.

I thought so, after a quick read of the code, that's too bad.
I'm sorry to learn about the tbb linkage issues, I can't understand how they could be related to this change, which LGTM.

Comment on lines 19 to 20
#include <gtest/gtest.h>
#include "sinsp_with_test_input.h"
#include <dns_manager.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

The rules for ordering the header files vary a lot from organization to organization. However, there is some consensus in the industry that the headers "closest" to the current compilation unit should go first, then more distant ones such as 3rd party libs and, finally, standard header files. The main reason is that including a system/library header file before the local ones might hide the fact that they miss a critical header for their internal definition, only to be sadly discovered by someone, at some later point in time, who uses these headers in a different context.
According to this idea GTest header should go last in this case.
It's your call whether you feel to embrace this.
As an aside, I think the ordering of headers should be put in the project's coding guidelines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes we need the coding guidelines as ... well style is all over the place.

@incertum incertum force-pushed the cleanup-dns-manager branch 4 times, most recently from 05fc130 to 0cb9311 Compare December 8, 2023 07:39
@incertum
Copy link
Contributor Author

incertum commented Dec 8, 2023

No idea about the CI, anyone having a clue why CI Build / build-shared-libs-linux-amd64 🧐 (pull_request) is failing?

Edit: That pipeline seems to be wonky across many PRs.

@Andreagit97 Andreagit97 added this to the 0.14.0 milestone Dec 11, 2023
@incertum incertum force-pushed the cleanup-dns-manager branch from 0cb9311 to 9c63937 Compare December 11, 2023 15:36
Co-authored-by: Federico Di Pierro <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
FedeDP
FedeDP previously approved these changes Dec 12, 2023
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 Dec 12, 2023

LGTM label has been added.

Git tree hash: 83baf17911bcd54fa34534fae83d2312d3a76e23

Copy link
Contributor

@gnosek gnosek left a comment

Choose a reason for hiding this comment

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

👍 some very minor questions

*/

#if defined(HAS_CAPTURE) && !defined(CYGWING_AGENT) && !defined(_WIN32) && !defined(__EMSCRIPTEN__)
#include "sinsp_with_test_input.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this include?

Copy link
Contributor

Choose a reason for hiding this comment

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

the test is not using it, so TEST_F(sinsp_with_test_input below is not really necessary.

Copy link
Member

Choose a reason for hiding this comment

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

When we remove this include I think we are ready to go, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

✔️ from me

TEST_F(sinsp_with_test_input, simple_dns_manager_invocation)
{
// Simple dummy test to assert that sinsp_dns_manager is invocated correctly
// and not leaking memory
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we run the test suite under valgrind in CI? Do we actually detect the (lack of) memory leak?

Copy link
Contributor

Choose a reason for hiding this comment

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

We run ASan in all libs tests, which will detect memory leaks.

@@ -195,7 +195,7 @@ void sinsp_dns_manager::cleanup()
{
m_exit_signal.set_value();
m_resolver->join();
m_resolver = NULL;
m_resolver.reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ouch. Good catch!

@gnosek
Copy link
Contributor

gnosek commented Dec 12, 2023

It seems that we need to keep using a pointer, but a smart pointer now as you can't otherwise truly check if std::thread is empty.

I thought so, after a quick read of the code, that's too bad.

std::optional might be an option (hee hee), not sure if it's worth the hassle though.

@poiana poiana requested a review from FedeDP December 12, 2023 16:18
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 poiana added the lgtm label Dec 12, 2023
@poiana
Copy link
Contributor

poiana commented Dec 12, 2023

LGTM label has been added.

Git tree hash: 2e477a958ad4add52209294e5110b773e5260e3f

@incertum
Copy link
Contributor Author

It seems that we need to keep using a pointer, but a smart pointer now as you can't otherwise truly check if std::thread is empty.

I thought so, after a quick read of the code, that's too bad.

std::optional might be an option (hee hee), not sure if it's worth the hassle though.

@gnosek Oh I would prefer not to mess too much with the dns manager as I never looked at it really 🤣
It likely should be refactored one of these days.

Copy link
Contributor

@LucaGuerra LucaGuerra left a comment

Choose a reason for hiding this comment

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

LGTM

@poiana
Copy link
Contributor

poiana commented Dec 12, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, incertum, LucaGuerra

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 [FedeDP,LucaGuerra,incertum]

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 1d4cabc into falcosecurity:master Dec 12, 2023
21 checks passed
@incertum incertum deleted the cleanup-dns-manager branch December 12, 2023 22:06
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.

7 participants