Skip to content

Non-deterministic contenthash generation #512

@bschmeck

Description

@bschmeck

We run a Rails app that is deployed to multiple webservers. During our deploy, we build packs on each machine from the same deployed code. We have very recently encountered an issue where this process has resulted in packs with different contenthash fingerprints in their filename. There are only 2 CSS files in the chunk, and it seems to be an issue of the order in which those modules are hashed when contenthash is being calculated.

  • Operating System: CentOS 8
  • Node Version: 10.19.0
  • NPM Version: 6.13.4
  • webpack Version: 4.41.5
  • mini-css-extract-plugin Version: 0.8.2

Expected Behavior

Building packs for the same code on multiple machines should generate identical contenthash filenames.

Actual Behavior

The modules associated with a chunk are hashed in a non-deterministic way, resulting in different fingerprints on different machines.

Code

How Do We Reproduce?

I'm still working on a reproducable example, but the issue appears to be the order in which chunk.modulesIterable returns modules here:

for (const m of chunk.modulesIterable) {
if (m.type === MODULE_TYPE) {
m.updateHash(hash);
}
}

modulesIterable is a SortableSet, but it appears that the code needs to explicitly call sort() on the set to retrieve values in order. Adding a call to chunk.modulesIterable.sort() before hashing the modules appears to be sufficient to generate a consistent fingerprint. If that seems to be a reasonable approach, I'm happy to open a PR but am struggling to put together a test for the change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions