Skip to content

Commit

Permalink
Merge pull request #183 from AlexEvanczuk/ae-address-cache-race-condi…
Browse files Browse the repository at this point in the history
…tion

Fix race condition in cache implementation
  • Loading branch information
rafaelfranca authored Mar 8, 2022
2 parents 70e4436 + ac60dd8 commit 0858c42
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/packwerk/run_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def initialize(

@file_processor = T.let(nil, T.nilable(FileProcessor))
@context_provider = T.let(nil, T.nilable(ConstantDiscovery))
@cache = T.let(nil, T.nilable(Cache))
# We need to initialize this before we fork the process, see https://github.com/Shopify/packwerk/issues/182
@cache = T.let(
Cache.new(enable_cache: @cache_enabled, cache_directory: @cache_directory, config_path: @config_path), Cache
)
end

sig { params(absolute_file: String).returns(T::Array[Packwerk::Offense]) }
Expand All @@ -89,7 +92,7 @@ def process_file(absolute_file:)

sig { returns(FileProcessor) }
def file_processor
@file_processor ||= FileProcessor.new(node_processor_factory: node_processor_factory, cache: cache)
@file_processor ||= FileProcessor.new(node_processor_factory: node_processor_factory, cache: @cache)
end

sig { returns(NodeProcessorFactory) }
Expand Down Expand Up @@ -118,11 +121,6 @@ def resolver
)
end

sig { returns(Cache) }
def cache
@cache ||= Cache.new(enable_cache: @cache_enabled, cache_directory: @cache_directory, config_path: @config_path)
end

sig { returns(PackageSet) }
def package_set
::Packwerk::PackageSet.load_all_from(@root_path, package_pathspec: @package_paths)
Expand Down

0 comments on commit 0858c42

Please sign in to comment.