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

Change WMISampler class to create a single thread, owned by the object #3987

Merged
merged 2 commits into from
Jun 28, 2019

Conversation

derekwbrown
Copy link
Contributor

What does this PR do?

Changes the implementation behavior or the WMISampler class, used to do WMI requests.

Old version created a new thread for each request, which in turn required CoInitialize() on that
new thread. This behavior apparently triggers a memory leak in win2016.

New implementation creates a single thread per WMISampler object instance. That thread just waits to be signaled, and when it does, it runs the WMI query. By doing this we

  • Ensure that the WMI queries for a given instance are always run on the same underlying win32 thread
  • Ensure that CoInitialize only needs to be called once per instance (at the beginning of the thread).

Motivation

Memory leak detected in agent core process

Review checklist (to be filled by reviewers)

  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached
  • Feature or bugfix must have tests
  • Git history must be clean
  • If PR adds a configuration option, it must be added to the configuration file.

that always does the WMI queries.  Only call CoInitialize once.

Attempt to not trigger apparent bug in win2016 which causes a memory
leak.
@derekwbrown derekwbrown requested review from truthbk and ofek June 26, 2019 17:56
@derekwbrown derekwbrown requested review from a team as code owners June 26, 2019 17:56
@therve
Copy link
Contributor

therve commented Jun 26, 2019

Not a full review, but as a general design comment I'd rather not inherit from Thread, and keep the class hierarchy as-is.

self._current_sample = self._query()

self._previous_sample = self._current_sample
self._current_sample = self._query()
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm being daft, self._query is never defined

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is defined here on line 433

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ty, I was misreading the deletion on line 145

@derekwbrown derekwbrown force-pushed the db/wmi_on_own_thread branch from 50cd0f6 to 82bfb7a Compare June 28, 2019 14:36
@derekwbrown derekwbrown force-pushed the db/wmi_on_own_thread branch from 82bfb7a to 91114ba Compare June 28, 2019 15:42
@ofek ofek merged commit 615de44 into master Jun 28, 2019
@ofek ofek deleted the db/wmi_on_own_thread branch June 28, 2019 16:54
@ofek ofek changed the title Change WMISampler class to create a single thread, owned by the object, Change WMISampler class to create a single thread, owned by the object Jun 28, 2019
ofek pushed a commit that referenced this pull request Jun 29, 2019
…t, (#3987)

* Change WMISampler class to create a single thread, owned by the object,
that always does the WMI queries.  Only call CoInitialize once.

Attempt to not trigger apparent bug in win2016 which causes a memory
leak.

* Fix improper initializaiton of `_sampling`
Fix import order
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