Land #9744, Add synchronization around public module metadata cache methods

4.x
Jeffrey Martin 2018-03-22 17:24:39 -05:00
parent 04fcbbc70f
commit a76a5ce83b
No known key found for this signature in database
GPG Key ID: 0CD9BBC2AF15F171
2 changed files with 14 additions and 8 deletions

View File

@ -24,17 +24,21 @@ class Cache
# Refreshes cached module metadata as well as updating the store # Refreshes cached module metadata as well as updating the store
# #
def refresh_metadata_instance(module_instance) def refresh_metadata_instance(module_instance)
@mutex.synchronize {
dlog "Refreshing #{module_instance.refname} of type: #{module_instance.type}" dlog "Refreshing #{module_instance.refname} of type: #{module_instance.type}"
refresh_metadata_instance_internal(module_instance) refresh_metadata_instance_internal(module_instance)
update_store update_store
}
end end
# #
# Returns the module data cache, but first ensures all the metadata is loaded # Returns the module data cache, but first ensures all the metadata is loaded
# #
def get_metadata def get_metadata
@mutex.synchronize {
wait_for_load wait_for_load
@module_metadata_cache.values @module_metadata_cache.values
}
end end
# #
@ -42,6 +46,7 @@ class Cache
# if there are changes. # if there are changes.
# #
def refresh_metadata(module_sets) def refresh_metadata(module_sets)
@mutex.synchronize {
unchanged_module_references = get_unchanged_module_references unchanged_module_references = get_unchanged_module_references
has_changes = false has_changes = false
module_sets.each do |mt| module_sets.each do |mt|
@ -75,8 +80,13 @@ class Cache
end end
update_store if has_changes update_store if has_changes
}
end end
#######
private
#######
# #
# Returns a hash(type->set) which references modules that have not changed. # Returns a hash(type->set) which references modules that have not changed.
# #
@ -102,10 +112,6 @@ class Cache
return skip_reference_name_set_by_module_type return skip_reference_name_set_by_module_type
end end
#######
private
#######
def remove_from_cache(module_name) def remove_from_cache(module_name)
old_cache_size = @module_metadata_cache.size old_cache_size = @module_metadata_cache.size
@module_metadata_cache.delete_if {|_, module_metadata| @module_metadata_cache.delete_if {|_, module_metadata|

View File

@ -23,6 +23,10 @@ module Msf::Modules::Metadata::Store
load_metadata load_metadata
end end
#######
private
#######
# #
# Update the module meta cache disk store # Update the module meta cache disk store
# #
@ -39,10 +43,6 @@ module Msf::Modules::Metadata::Store
end end
end end
#######
private
#######
def load_metadata def load_metadata
begin begin
retries ||= 0 retries ||= 0