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

Allow constants to load from DRb threads #10038

Merged
merged 2 commits into from Jul 26, 2016

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Jul 25, 2016

Purpose or Intent

The serialization of Automate calls done with a Mutex in PR #9903 was causing Automate methods to hang because constants couldn't be loaded by DRb requests which are called by Automate Methods.

Links

Steps for Testing/QA

[Optional] Difficult to reproduce

https://bugzilla.redhat.com/show_bug.cgi?id=1354054

use ActiveSupport::Dependencies.interlock.permit_concurrent_loads
to allow for Automate Methods/Drb to load symbols
# This was added because in RAILS 5 PUMA sends multiple requests
# to the same processa and our DRb server implementation for Automate
# Methods is not thread safe. The permit_concurrent_loads allows the
# DRb requests which run in different threads to load symbols.
Copy link
Member

Choose a reason for hiding this comment

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

@mkanoor I don't understand the wording of "load symbols", "allow symbols to load". Is this strictly about loading constants via rails autoload? I'm fine with this change, I just don't understand the language of the PR.

Copy link
Member

Choose a reason for hiding this comment

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

@mkanoor Do you mean to "autoload models"? "load symbols" also doesn't make sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fryguy @jrafanie
If there are constants missing Rails has to load them when the Drb thread is running. Without the permit_concurrent_loads the Rails thread would get blocked and the process hangs. So these are not really auto-load, if we had loaded them all upfront we wouldn't have seen this issue, these constants come about when some of the constants are missing and Rails tries to load them.

Copy link
Member

Choose a reason for hiding this comment

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

The term "Rails const_missing" is synonymous with "Rails autoload" ... "load symbols" is confusing because a symbol is like :symbol...those don't "load"

Copy link
Member

Choose a reason for hiding this comment

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

So these are not really auto-load, if we had loaded them all upfront we wouldn't have seen this issue, these constants come about when some of the constants are missing and Rails tries to load them.

Right, @mkanoor. "Loading constants" is clearer than "loading symbols".

The key point is if you don't eager load all constants to be used in your automate "methods/dialogs/things" and rely on Rails to autoload those missing constants, you could encounter a race condition with multiple threads, where the holders of two locks cause a deadlock:

  • ActiveSupport::Dependencies.interlock
  • @deliver_mutex

This permit_concurrent_loads allows constant loading by yielding 'share' locks to avoid deadlocks:

+      # Temporarily give up all held Share locks while executing the
+      # supplied block, allowing any +compatible+ exclusive lock request
+      # to proceed.

From here

@mkanoor mkanoor changed the title Allow symbols to load from DRb threads Allow constants to load from DRb threads Jul 25, 2016
@miq-bot
Copy link
Member

miq-bot commented Jul 25, 2016

Checked commits mkanoor/manageiq@a1656fc~...d0aefaf with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
1 file checked, 0 offenses detected
Everything looks good. 🍰

@jrafanie
Copy link
Member

LGTM

@Fryguy
Copy link
Member

Fryguy commented Jul 25, 2016

👍

@gmcculloug gmcculloug merged commit 6bad915 into ManageIQ:master Jul 26, 2016
@gmcculloug gmcculloug added this to the Sprint 44 Ending Aug 1, 2016 milestone Jul 26, 2016
chessbyte pushed a commit that referenced this pull request Jul 26, 2016
Allow constants to load from DRb threads
(cherry picked from commit 6bad915)
@chessbyte
Copy link
Member

Darga backport details:

commit d8071994c7ffe240d8ed4a600dee3973dfa6fa15
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Mon Jul 25 21:40:55 2016 -0400

    Merge pull request #10038 from mkanoor/bugzilla_1354054_round2

    Allow constants to load from DRb threads
    (cherry picked from commit 6bad91538d296de1f7efe4e70dd44a767450d8f3)

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.

None yet

6 participants