Class: RuboCop::Cop::Legion::Framework::MutexNestedSync

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/framework/mutex_nested_sync.rb

Overview

Detects ‘synchronize` blocks nested inside other `synchronize` blocks, which risks deadlock if the same mutex is re-acquired. Even with different mutexes, nested locks require consistent ordering to avoid deadlock.

Examples:

# bad
@mutex.synchronize do
  @other_mutex.synchronize do
    work
  end
end

# good — flatten into a single lock or use a dedicated lock object
@mutex.synchronize do
  work
end

Constant Summary collapse

MSG =
'Nested `synchronize` detected. Risk of deadlock if the same mutex is re-acquired ' \
'or if lock ordering is inconsistent.'

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



28
29
30
31
32
33
# File 'lib/rubocop/cop/legion/framework/mutex_nested_sync.rb', line 28

def on_block(node)
  return unless synchronize_call?(node)
  return unless nested_inside_synchronize?(node)

  add_offense(node.send_node)
end