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

Thread safe loader 2 #48598

Closed
wants to merge 15 commits into from
Closed

Conversation

mattp-
Copy link
Contributor

@mattp- mattp- commented Jul 16, 2018

What does this PR do?

this is a version of #45782 with latest develop merged in. I've not made any changes other than resolving merge conflicts; the original jenkins results have aged out so I'm creating this to re-run. If I figure out a solution I'll send PR to @smarsching and close this.

What issues does this PR fix or reference?

Previous Behavior

Remove this section if not relevant

New Behavior

Remove this section if not relevant

Tests written?

Yes/No

Commits signed with GPG?

Yes/No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

There was a race condition in the salt loader when injecting global
values (e.g. "__pillar__" or "__salt__") into modules. One effect of
this race condition was that in a setup with multiple threads, some
threads may see pillar data intended for other threads or the pillar
data seen by a thread might even change spuriously.

There have been earlier attempts to fix this problem (saltstack#27937, saltstack#29397).
These patches tried to fix the problem by storing the dictionary that
keeps the relevant data in a thread-local variable and referencing this
thread-local variable from the variables that are injected into the
modules.

These patches did not fix the problem completely because they only
work when a module is loaded through a single loader instance only.
When there is more than one loader, there is more than one
thread-local variable and the variable injected into a module is
changed to point to another thread-local variable when the module is
loaded again. Thus, the problem resurfaced while working on saltstack#39670.

This patch attempts to solve the problem from a slightly different
angle, complementing the earlier patches: The value injected into the
modules now is a proxy that internally uses a thread-local variable to
decide to which object it points. This means that when loading a module
again through a different loader (possibly passing different pillar
data), the data is actually only changed in the thread in which the
loader is used. Other threads are not affected by such a change.

This means that it will work correctly in the current situation where
loaders are possibly created by many different modules and these
modules do not necessary know in which context they are executed. Thus
it is much more flexible and reliable than the more explicit approach
used by the two earlier patches.

Unfortunately, the stand JSON and Msgpack serialization code cannot
handle proxied objects, so they have to be unwrapped before passing them
to that code.

The salt.utils.json module has been modified to  takes care of
unwrapping objects that are proxied using the ThreadLocalProxy.

The salt.utils.msgpack module has been added and basically provides the
same functions as the salt.utils.json module, but for msgpack. Like the
json module, it takes care of unwrapping proxies.
@mattp- mattp- requested a review from a team as a code owner July 16, 2018 00:20
@ghost ghost requested review from a team July 16, 2018 00:20
@damon-atkins
Copy link
Contributor

Go Go Jenkins!

Copy link
Contributor

@DmitryKuzmenko DmitryKuzmenko left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@gtmanfred gtmanfred left a comment

Choose a reason for hiding this comment

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

LGTM, needs the versionadded references updated to Fluorine.

blind-review


def pack(o, stream, **kwargs):
'''
.. versionadded:: Oxygen
Copy link
Contributor

Choose a reason for hiding this comment

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

Fluorine


def packb(o, **kwargs):
'''
.. versionadded:: Oxygen
Copy link
Contributor

Choose a reason for hiding this comment

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

Fluorine


def unpack(stream, **kwargs):
'''
.. versionadded:: Oxygen
Copy link
Contributor

Choose a reason for hiding this comment

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

Fluorine


def unpackb(packed, **kwargs):
'''
.. versionadded:: Oxygen
Copy link
Contributor

Choose a reason for hiding this comment

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

Fluorine

Proxy object that can reference different values depending on the current
thread of execution.

..versionadded:: Oxygen
Copy link
Contributor

Choose a reason for hiding this comment

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

Fluorine

@gtmanfred
Copy link
Contributor

Also, looks like there are some pylint warnings in salt/state.py https://jenkinsci.saltstack.com/job/pr-lint/job/PR-48598/1/warnings52Result/

@mattp- mattp- force-pushed the thread-safe-loader-2 branch from eefaa64 to 8fbb40b Compare July 16, 2018 16:33
@mattp- mattp- closed this Jul 16, 2018
@mattp- mattp- reopened this Jul 16, 2018
@@ -433,7 +433,14 @@ def __del__(self):
def connect(self):
if not self.auth.authenticated:
yield self.auth.authenticate()
self.publish_port = self.auth.creds['publish_port']

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused about the relationship between loader thread-safety and these proposed changes to the transports.

@mattp-
Copy link
Contributor Author

mattp- commented Jul 16, 2018 via email

@cachedout cachedout removed the request for review from a team July 16, 2018 22:11
@cachedout
Copy link
Contributor

@isbm Does anybody on @saltstack/team-suse want to review this? We're getting close to merging this in.

@cachedout
Copy link
Contributor

@mattp- Can you rebase against the head of develop so we have only the related changes? That should clear out those transport changes so we know exactly what we're dealing with here.

@mattp-
Copy link
Contributor Author

mattp- commented Jul 16, 2018

@cachedout yep will do shortly. to be clear I haven't made any changes yet; though I did notice one incompatibility between how data.serializers.msgpack and data.utils.msgpack is handled that I need to look at more.

@mattp- mattp- force-pushed the thread-safe-loader-2 branch from 46d2b5e to 1215422 Compare July 16, 2018 23:10
@mattp-
Copy link
Contributor Author

mattp- commented Jul 16, 2018

unassociated commit removed

@cachedout
Copy link
Contributor

@mattp- Cool. We also need the issues raised by @gtmanfred resolved before we can move forward, please.

Copy link
Contributor

@isbm isbm left a comment

Choose a reason for hiding this comment

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

LGTM

@rallytime
Copy link
Contributor

Something isn't right here. The test suite is not running the tests. @mattp- Can you take a look at the console output from the test run? It's having trouble in test-daemon startup: https://jenkinsci.saltstack.com/job/pr-kitchen-ubuntu1604-py2/job/PR-48598/5/console

@mattp- mattp- closed this Jul 17, 2018
@mattp- mattp- reopened this Jul 17, 2018
salt.serializers.msgpack indirectly calls it down the stack, alongside other
backcompat managament.
@cachedout
Copy link
Contributor

@gtmanfred Re-review requested please.

@cachedout
Copy link
Contributor

I spent some time looking at this today and I'm honestly not sure what's happening. It's failing in different ways on different platforms and, oddly enough, it seems to work just fine on my development machine.

@mattp-
Copy link
Contributor Author

mattp- commented Nov 27, 2018

closing in favor of #50648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants