From 228be78ae3cc5d1a6a08300a6403574ea0755c63 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Sun, 4 Jul 2021 00:48:36 +0900 Subject: [PATCH] fix remote timeout error. The reason of timeout error is seeing different Queue in readline method accidentally. To fix it, setup Queues at the beggining of accept block. In addition, use rdbg on UNIX domain socket. --- lib/debug/server.rb | 23 +++++++++++++++++------ test/support/utils.rb | 6 +++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/debug/server.rb b/lib/debug/server.rb index 13a257d08..d08e6b788 100644 --- a/lib/debug/server.rb +++ b/lib/debug/server.rb @@ -15,8 +15,8 @@ def initialize @accept_m = Mutex.new @accept_cv = ConditionVariable.new @client_addr = nil - @q_msg = Queue.new - @q_ans = Queue.new + @q_msg = nil + @q_ans = nil @unsent_messages = [] @width = 80 @@ -38,6 +38,9 @@ def initialize @sock.puts m } @unsent_messages.clear + + @q_msg = Queue.new + @q_ans = Queue.new } setup_interrupt do @@ -50,7 +53,9 @@ def initialize DEBUGGER__.message "Disconnected." @sock = nil @q_msg.close + @q_msg = nil @q_ans.close + @q_ans = nil end end end @@ -83,9 +88,6 @@ def greeting end def process - @q_msg = Queue.new - @q_ans = Queue.new - pause while line = @sock.gets @@ -143,7 +145,15 @@ def sock skip: false if s = @sock # already connection # ok elsif skip == true # skip process - return yield nil + no_sock = true + r = @accept_m.synchronize do + if @sock + no_sock = false + else + yield nil + end + end + return r if no_sock else # wait for connection until s = @sock @accept_m.synchronize{ @@ -192,6 +202,7 @@ def puts str = nil def readline (sock do |s| s.puts "input" + sleep 0.01 until @q_msg @q_msg.pop end || 'continue').strip end diff --git a/test/support/utils.rb b/test/support/utils.rb index 5a211c29f..95808c7a3 100644 --- a/test/support/utils.rb +++ b/test/support/utils.rb @@ -60,16 +60,15 @@ def debug_on_local boot_options def debug_on_unix_domain_socket repl_prompt = '(rdbg:remote)' @mode = 'UNIX DOMAIN SOCKET' - boot_options = '-r debug/open' cmd = "#{__dir__}/../../exe/rdbg -A" - setup_remote_debuggee("#{RUBY} #{boot_options} #{temp_file_path}") + setup_remote_debuggee("#{__dir__}/../../exe/rdbg -O -- #{temp_file_path}") run_test_scenario(cmd, repl_prompt) end def debug_on_tcpip repl_prompt = '(rdbg:remote)' @mode = 'TCP/IP' cmd = "#{__dir__}/../../exe/rdbg -A #{RUBY_DEBUG_TEST_PORT}" - setup_remote_debuggee("#{__dir__}/../../exe/rdbg -O --port=#{RUBY_DEBUG_TEST_PORT} #{temp_file_path}") + setup_remote_debuggee("#{__dir__}/../../exe/rdbg -O --port=#{RUBY_DEBUG_TEST_PORT} -- #{temp_file_path}") run_test_scenario(cmd, repl_prompt) end @@ -103,6 +102,7 @@ def run_test_scenario(cmd, repl_prompt) write.puts(cmd) cmd = @queue.pop end + write.puts(cmd) @last_backlog.clear next # INTERNAL_INFO shouldn't be pushed into @backlog and @last_backlog