This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 113007 - Debugging session cannot be killed on Windows
Summary: Debugging session cannot be killed on Windows
Status: VERIFIED FIXED
Alias: None
Product: ruby
Classification: Unclassified
Component: Debugger (show other bugs)
Version: 6.x
Hardware: PC Windows Vista
: P1 blocker (vote)
Assignee: Martin Krauskopf
URL: http://jira.codehaus.org/browse/JRUBY...
Keywords: REGRESSION
Depends on:
Blocks:
 
Reported: 2007-08-16 15:16 UTC by Tomas Danek
Modified: 2007-11-07 14:15 UTC (History)
0 users

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Danek 2007-08-16 15:16:45 UTC
Product Version: NetBeans IDE Dev (Build 200708160000) Java: 1.6.0_02; Java HotSpot(TM) Client VM 1.6.0_02-b05 System:
Windows Vista version 6.0 running on x86; Cp1250; cs_CZ (nb) Userdir: C:\Users\tester\.netbeans\dev
--------------------------------------

jruby+classic+vista

- start IDE with fresh UD, generate new ruby project, use jruby
- put breakpoint to line with puts
- run debugger
- when it stops, kill it by shift-f5
- session is not killed (in task manager i see java running, i have to kill it there)

there were similar bugs to this, but i did not find any opened, so filing this new one (100% reproducible)

note: finishing debugger in ordinary way (i.e. in this case e.g. to push f8 works fine, session  finishes)
Comment 1 Martin Krauskopf 2007-08-16 15:20:19 UTC
Only Vista, XP works correctly? Thanks for helping since I do not have easy access to Win machines.
Comment 2 Tomas Danek 2007-08-16 15:56:29 UTC
For now, i have access only to win vista, i will try on XP ASAP. 

here's the log from vista:

FINEST [org.netbeans.modules.ruby.debugger.Util]: Using timeout: 10s
FINE [org.rubyforge.debugcommons.Util]: Running [basedir:
C:\Users\tester\Documents\NetBeansProjects\RubyApplication4\lib]: "C:\Program Files\NetBeans 6.0
200708160000\ruby1\jruby-1.0\bin\jruby.bat -IC:\Users\tester\Documents\NetBeansProjects\RubyApplication4\lib
-IC:\Users\tester\Documents\NetBeansProjects\RubyApplication4\test -I C:\Program Files\NetBeans 6.0
200708160000\ruby1\ruby\debug-commons-0.9.4 -r C:\Users\tester\AppData\Local\Temp\classic-debug23160.rb -r
C:\Users\tester\AppData\Local\Temp\io-synchronizer23161.rb -r classic-debug.rb
C:\Users\tester\Documents\NetBeansProjects\RubyApplication4\lib\main.rb"
FINEST [org.rubyforge.debugcommons.Util]: MK>
org.rubyforge.debugcommons.RubyDebuggerProxy.attach(RubyDebuggerProxy.java:394) called...., 1187276053349
FINEST [org.rubyforge.debugcommons.Util]: MK>   finished: "false"
FINEST [org.rubyforge.debugcommons.Util]: Cannot connect to localhost:51390. Trying again...(19)
FINE [org.rubyforge.debugcommons.Util]: Sending command debugger: b
C:\Users\tester\Documents\NetBeansProjects\RubyApplication4\lib\main.rb:10
FINE [org.rubyforge.debugcommons.Util]: Starting ReadersSupport readloop: class
org.rubyforge.debugcommons.ReadersSupport command loop
FINE [org.rubyforge.debugcommons.Util]: Sending command debugger: cont
FINEST [org.rubyforge.debugcommons.Util]: Waiting for breakpoints.
FINEST [org.rubyforge.debugcommons.Util]: Breakpoint at main.rb:10, threadId: 1
FINE [org.rubyforge.debugcommons.Util]: udpating threads
FINE [org.rubyforge.debugcommons.Util]: Sending command debugger: th l
FINE [org.rubyforge.debugcommons.Util]: Sending command debugger: th 1; w
FINEST [org.netbeans.modules.ruby.debugger.Util]: Performing "kill"
FINEST [org.netbeans.modules.ruby.debugger.Util]: Finishing session: localhost:51390
FINE [org.rubyforge.debugcommons.Util]: Sending command debugger: exit
INFO [org.rubyforge.debugcommons.Util]: finished
FINE [org.rubyforge.debugcommons.Util]: Got <message>, text == finished
FINE [org.rubyforge.debugcommons.Util]: ReadersSupport readloop [class org.rubyforge.debugcommons.ReadersSupport command
loop] successfully finished.
FINE [org.rubyforge.debugcommons.Util]: Trying to finish the same proxy more than once:
org.rubyforge.debugcommons.RubyDebuggerProxy@16fd116
FINEST [org.rubyforge.debugcommons.Util]: Socket reader loop finished.
Comment 3 Martin Krauskopf 2007-08-16 16:07:36 UTC
That's strange. Since there really seems to be 'exit' called on the debuggee side. Only what comes to my mind is that
there were IOError before 'exit' call was reached (2 calls). I'll put the exit into the 'ensure' block in both backends.
Comment 4 Martin Krauskopf 2007-08-16 16:19:02 UTC
Aren't there some errors in the output window?

Could you try to apply this patch to the context.rb (in $NB_BIN/ruby1/ruby/debug-commons-0.9.4) and let me know whether
does it help? Thanks.

  --- contecxt-new.rb	2007-08-08 15:14:54.000000000 +0200
  +++ context.rb	2007-08-16 17:03:09.000000000 +0200
  @@ -447,10 +447,13 @@
          end
          
        when /^\s*exit$/
  -        @printer.print_message("finished")
  -        debug_commons_set_trace_func nil
  -        @socket.close
  -        exit!
  +        begin
  +          @printer.print_message("finished")
  +          debug_commons_set_trace_func nil
  +          @socket.close
  +        ensure
  +          exit!
  +        end
  
        else
          @printer.print_message("Unknown input: %s", input)

Comment 5 Tomas Danek 2007-08-16 17:49:37 UTC
nope, the patch did not help:(

output window (verbose)

Socket connection established.
Starting command reader loop.
ruby 1.8.5 debugger listens on port 54601
Setting trace func: #&lt;Proc:0xf1916f&gt;
Debugging not yet started.
Debugging not yet started.
READ b C:\Users\tester\Documents\NetBeansProjects\RubyApplication7\lib\main.rb:10
Using context for main thread : #&lt;Thread:0xb42cbf&gt;
Processing b C:\Users\tester\Documents\NetBeansProjects\RubyApplication7\lib\main.rb:10, binding=
<breakpointAdded no="1" location="main.rb:10"/>
READ cont
<breakpoint file="main.rb" line="10" threadId="1"/>
debug_command, @stop_next=-1, @frames.size=1
Suspending : #&lt;Thread:0xb42cbf&gt;
READ th l
Using context for main thread : #&lt;Thread:0xb42cbf&gt;
Processing th l, binding=#&lt;Binding:0x18aab40&gt;
<threads>
<thread id="1" status="sleep"/>
</threads>
READ th 1; w
Using context for thread: 1
Processing w, binding=#&lt;Binding:0x18aab40&gt;
<frames>
<frame no="1" file="C:\Users\tester\Documents\NetBeansProjects\RubyApplication7\lib\main.rb" line="10"/>
</frames>
READ exit
Using context for main thread : #&lt;Thread:0xb42cbf&gt;
Processing exit, binding=#&lt;Binding:0x18aab40&gt;
<message>finished</message>
Comment 6 Tomas Danek 2007-08-21 15:56:15 UTC
Reproducible also on XP. 
Comment 7 Torbjorn Norbye 2007-08-22 05:08:52 UTC
I'm not sure if this is the problem, but I thought I'd mention it just in case it's helpful:  Killing JRuby processes
does not work if the JRuby launching scripts are used (bin/jruby and bin/jruby.bat). The Unix script might have been
fixed (by changing their fork of the Java VM to use an exec, but this wasn't done on Windows).

The problem is that NetBeans launches JRuby, and JRuby in turn launches the VM process. When NetBeans process-kills the
JRuby process it started, it's really only killing the jruby launcher script process, and the grandchild process (the
actual JRuby VM process) is left running. The java.lang.Process api doesn't give us any more control or ability to find
other processes to kill (or even the process group).

To work around this, the RubyExecutor bypasses the JRuby script, since it's not necessary anyway (we know what it's
going to do), and launches the Java VM directly such that it has complete control in killing it.

Somebody (it could have been Tomas) just mentioned somewhere else that the debugger is bypassing this mechanism and is
really launching the jruby script. If so, that -might- explain what the problem is; perhaps you can track down the
jruby.bat problem and get it fixed, or if not, figure out if there's a simple way to get the debugger to also use the VM
launching directly.
Comment 8 Martin Krauskopf 2007-08-22 06:16:57 UTC
> .... 'use VM instead of starting script'....

Yes, I'm starting interpreter directly (jruby.bat). But this what I want to stay with as long as possible. I want to
keep debug-commons clear from special handling of specific interpreters. Because of that I'm sending debugger command
which causes 'exit!' to be called directly on the debuggee side when finish is forced. This stopped to work for some
reasons. (and it works reliably few days ago).
Comment 9 Martin Krauskopf 2007-08-23 14:18:50 UTC
Under some circumstances 'Kernel.exit!' or 'Thread.main.exit!' does not exit. I've also got 'exit' call to _not_ working
under Linux:

====
  terminator = Thread.new do
    sleep 2
    puts 'exit'
    exit!
  end
  Kernel.module_eval(<<-"end;"
        alias_method(:debug_commons_set_trace_func, :set_trace_func)
        def set_trace_func(proc)
          raise "Cannot call 'set_trace_func' method during debugging session."
        end
    end;
  )
  debug_commons_set_trace_func(lambda do |_, _, _, _, _, _|
    next if Thread.current == terminator
    loop do
      puts Thread.current.object_id
      sleep 1
    end
  end)
  p "whatever...."
====

Probably problem is in handling of 'next' in the JRuby. I'll file a bug into the JRuby and try to evaluate further for
some workaround.
Comment 10 Martin Krauskopf 2007-08-23 16:28:32 UTC
I've filed issue for the JRuby: http://jira.codehaus.org/browse/JRUBY-1286. Will wait for evaluation.
Comment 11 Martin Krauskopf 2007-09-20 15:24:36 UTC
I've did more analysis and found much easier test-case which shows exit does not work under Windows and Linux in JRuby.
I've added comment to the JIRA issue. Changing this to task. I'll watch the progress in JRuby and possibly will do
appropriate changes in NetBeans if some are needed.
Comment 12 Martin Krauskopf 2007-11-02 12:54:12 UTC
With JRuby 1.0.2 this should be fixed.
Comment 13 Tomas Danek 2007-11-07 14:15:10 UTC
verified on XP, build with jruby 1.0.2