From b17b263cc73f08abcc04b6b3ab9d202a9306256a Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 13 Nov 2014 09:49:08 -0600 Subject: [PATCH] Ignore debugger threads MSP-11147 When using the debugger, it adds a thread that should be allowed and not go towards the count. --- lib/metasploit/framework/spec/threads/suite.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/metasploit/framework/spec/threads/suite.rb b/lib/metasploit/framework/spec/threads/suite.rb index 2a4b81ced3..99ef3a636a 100644 --- a/lib/metasploit/framework/spec/threads/suite.rb +++ b/lib/metasploit/framework/spec/threads/suite.rb @@ -31,7 +31,7 @@ module Metasploit unless @configured RSpec.configure do |config| config.before(:suite) do - thread_count = Thread.list.count + thread_count = Metasploit::Framework::Spec::Threads::Suite.non_debugger_thread_list.count # check with if first so that error message can be constructed lazily if thread_count > EXPECTED_THREAD_COUNT_AROUND_SUITE @@ -68,7 +68,7 @@ module Metasploit f.puts 'after(:suite)' end - thread_list = Thread.list + thread_list = Metasploit::Framework::Spec::Threads::Suite.non_debugger_thread_list thread_uuids = thread_list.map { |thread| thread[Metasploit::Framework::Spec::Threads::Suite::UUID_THREAD_LOCAL_VARIABLE] @@ -195,6 +195,15 @@ module Metasploit lines_by_thread_uuid end + + # @return + def self.non_debugger_thread_list + Thread.list.reject { |thread| + # don't do `is_a? Debugger::DebugThread` because it requires Debugger::DebugThread to be loaded, which it + # won't when not debugging. + thread.class.name == 'Debugger::DebugThread' + } + end end end end