Skip to content

pathUtils | joinCache memory leak #414

@Galcarmi

Description

@Galcarmi

Hey guys,

We use webpack in our services to bundle code.
A webpack compiler is being created for each bundling process by importing webpack creator function from webpack.
Webpack is using enhanced-resolve to resolve module paths.. We also have custom resolvers that extends ResolvePluginInstance which is a enhanced-resolve resolver AFAIK.
Those resolvers are injected to webpack using the plugins property

After a while, we saw that as the service bundle code a memory leak is increasing in our service.
(for each bundle a new compiler of webpack is created)

As you can see in the heap-dump picture, it is related to joinCache property.
Screenshot 2024-04-24 at 15 05 00

This property can be found here. this is a non-exported global variable that never cleans.

As I can see it, you can help us in 2 ways,

  1. Clean this Map every X interval (it will be amazing if you can provide a configuration for it)
  2. Provide a function that cleans that cache and we will call it after every bundle process.

LMK if you need any further data/explanations,
Thanks 🙏🏼🙏🏼

Activity

alexander-akait

alexander-akait commented on Apr 24, 2024

@alexander-akait
Member

Oh, it was for cache, how many run do you have?

Galcarmi

Galcarmi commented on Apr 25, 2024

@Galcarmi
Author

@alexander-akait The service runs (potentially) infinite bundling processes

Galcarmi

Galcarmi commented on Apr 25, 2024

@Galcarmi
Author

I can create a PR for adding a clearCache function, WDYT?

By the way, there is a third option to use LRU cache object with fixed size

Galcarmi

Galcarmi commented on Apr 29, 2024

@Galcarmi
Author
linked a pull request that will close this issue on Apr 30, 2024
Galcarmi

Galcarmi commented on Apr 30, 2024

@Galcarmi
Author

created a fork with the fix
#418
i'll try it on my servers and update..

Galcarmi

Galcarmi commented on May 2, 2024

@Galcarmi
Author

Well, seems like it works, can we do something similar for enhanced-resolve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexander-akait@Galcarmi

      Issue actions

        pathUtils | joinCache memory leak · Issue #414 · webpack/enhanced-resolve