Problem/Motivation

On automatic deployment for a project hosted on multiple servers with redis and varnish, we bump into a race condition issue when we add a new contrib module in the composer.json and enable it in the same commit.

The import failed due to the following reasons:
Unable to install the [CONTRIB_MODULE] module since it does not exist.

What happens is that during the deploy steps the caches are filled (after getting cleared) from the production website which doesn't yet contain the new module in its codebase. drush cim is then performed on code that expects this module.

Steps to reproduce locally

  • drush pmu -y [CONTRIB_MODULE]
  • mv web/modules/contrib/[CONTRIB_MODULE] [CONTRIB_MODULE]
  • drush cr
  • reload a page on you local project to fill the cache
  • mv [CONTRIB_MODULE] web/modules/contrib/[CONTRIB_MODULE]
  • drush cim -y

Proposed resolution

The problem is in core/lib/Drupal/Core/Config/ConfigImporter.php because on config import, drush doesn't explicitly perform a ->reset() on the module list. On drush enable for example, drush does explicitly reset the module list before grabbing it.

Will attach patch in comment.

Remaining tasks

Reviewing.

Issue fork drupal-3312001

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

stijndmd created an issue. See original summary.

stijndmd’s picture

Status: Active » Needs review
StatusFileSize
new712 bytes

Attached a patch which makes sure the module list is reset immediately before performing the extension updates of the config import.

stijndmd’s picture

Issue summary: View changes
catch’s picture

Status: Needs review » Needs work

I've seen similar during local development, usually it's because I forgot a step changing branches, but I think the reset would save a drush cr every so often.

I think this might be a trivial enough fix we could commit it without test coverage, however we should at least add a comment explaining the situation we're fixing.

davidjguru made their first commit to this issue’s fork.

stijndmd’s picture

Something like this is enough or do we need a longer explanation + issue link?

stijndmd’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work

I ran into this exact issue today during a deployment.

I think we should keep the original line as-is and add $this->moduleExtensionList->reset(); before with an explicit comment as to why we are resetting. Otherwise, without test coverage, we risk losing the ->reset() in a future refactor.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new611 bytes
new905 bytes

Made changes as per comment #8, please review.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

I think that's fine. It's hard to explain the race condition in a succinct comment, but the git log will point back to this issue if anyone wants to read more.

catch’s picture

Maybe something like:

Reset the module list in case a stale cache item has been set by another process during deployment for the comment?

stijndmd’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new664 bytes

Changed the comment.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

That works for me. Thanks!

stijndmd’s picture

Here's one with a correction since the previous didn't apply

ravi.shankar’s picture

StatusFileSize
new665 bytes
new742 bytes

Fixed the issue of line closing before 80 characters, this should be good to to now.

Maintaining the same status RTBC.

  • catch committed 437d535 on 9.4.x
    Issue #3312001 by stijndmd, ravi.shankar, davidjguru, longwave, catch:...
  • catch committed f6904c8 on 9.5.x
    Issue #3312001 by stijndmd, ravi.shankar, davidjguru, longwave, catch:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, cherry-picked back through to 9.4.x, thanks!

  • catch committed 3b119f2 on 10.0.x
    Issue #3312001 by stijndmd, ravi.shankar, davidjguru, longwave, catch:...
  • catch committed fc46f78 on 10.1.x
    Issue #3312001 by stijndmd, ravi.shankar, davidjguru, longwave, catch:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.