astashov / vim-ruby-debugger

Vim plugin for debugging Ruby applications (using ruby-debug-ide gem)
435 stars 36 forks source link

debugger starts but webserver doesn't listen to 3000 under OsX #26

Closed fwoeck closed 15 years ago

fwoeck commented 15 years ago

Hi,

I can't get the debugger working with MacVim (actual Snapshot 45) under OsX. Two processes are startet (see below), but webrick doesn't listen anywhere (at least where I was looking for it).

two ruby-processes:

fw 493 0.2 0,2 607008 6832 ?? S 4:44pm 0:02.49 ruby /Users/fw/.vim/bin/ruby_debugger.rb localhost 39767 39768 Vim VIM /Users/fw/.vim/tmp/ruby_debugger posix

fw 490 0.2 0,2 610664 10044 ?? S 4:44pm 0:02.87 /opt/local/bin/ruby /opt/local/bin/rdebug-ide -p 39767 -- script/server webrick

their open ports:

ruby 493 fw 7u IPv6 0x6ed8720 0t0 TCP localhost:49366->localhost:39767 (ESTABLISHED) ruby 493 fw 8u IPv6 0x6ed8258 0t0 TCP localhost:39768 (LISTEN)

ruby 490 fw 7u IPv6 0x6ed7664 0t0 TCP *:39767 (LISTEN) ruby 490 fw 8u IPv6 0x6ed84bc 0t0 TCP localhost:39767->localhost:49366 (ESTABLISHED)

with no port 3000 open.

the logfiles:

2009/06/26 16:43:55 Set breakpoint to: /Users/fw/devel/rwatch/app/views/rwatches/index.erb:12

2009/06/26 16:44:01 Start debugger

Fast Debugger (ruby-debug-ide 0.4.6) listens on :39767

-- Frank

astashov commented 15 years ago

Hi, Frank!

Is your app started successfully without vim-ruby-debugger (with usual script/server)? Also, can you try these steps:

  1. Go to page with your app.
  2. :Rdebugger
  3. Set breakpoint somewhere. and after these, send output of files ~/.vim/tmp/ruby_debugger_output, ~/.vim/tmp/ruby_debugger, ~/.vim/tmp/ruby_debugger_log to me.

Thanks!

fwoeck commented 15 years ago

Hi Anton,

thank you for your patience :) Actually the setting (gem-versions, source-code, .vim-Files) work under Ubuntu 8.10.

What's weird about the story is, that now, that I try it again, the picture changed: a) webbrick starts on 3000 and is accessible, b) in mvim, the breakpoint that I set before, remains red, so I can not continue the run c) when I try to remove the breakpoint, I get this errors: http://img.skitch.com/20090703-q2aye9r13thjs1hsxehpfkh55e.png

d) these are the logs:

tmp(master) > ll total 24 -rw-r--r-- 1 fw staff 106B 3 Jul 09:29 ruby_debugger -rw-r--r-- 1 fw staff 139B 3 Jul 09:29 ruby_debugger_log -rw-r--r-- 1 fw staff 372B 3 Jul 09:29 ruby_debugger_output tmp(master) > cat *

2009/07/03 09:29:11 Start debugger 2009/07/03 09:29:32 Set breakpoint to: /Users/fw/devel/rwatch/app/controllers/rwatches_controller.rb:22 Fast Debugger (ruby-debug-ide 0.4.6) listens on :39767 => Booting WEBrick => Rails 2.3.2 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2009-07-03 07:29:16] INFO WEBrick 1.3.1 [2009-07-03 07:29:16] INFO ruby 1.8.7 (2009-06-12) [i686-darwin9] [2009-07-03 07:29:16] INFO WEBrick::HTTPServer#start: pid=44099 port=3000 tmp(master) >

e) some gems: tmp(master) > gem list --local ruby-debug

* LOCAL GEMS *

ruby-debug (0.10.3) ruby-debug-base (0.10.3) ruby-debug-ide (0.4.6)

I will re-check, wheter I can reproduce the error on a different Mac and post this later today.

--Frank

astashov commented 15 years ago

Argh, I even don't know why you get these errors. :( But all worked well before, right? (I remember you opened the issue with RdbCommand). Maybe you changed something and then these nasty things started?

And these steps you described in comment above are happened on Mac, right? It works well on Linux, right? There is a trouble - I don't have Mac and I can't try to reproduce the issue on Mac...

fwoeck commented 15 years ago

The issue with the RdbCommand happened on an Ubuntu machine. All tests including the ones I described in this thread work under Linux. The issues do just occur under OsX/MacVim.

I did another test with a more or less "plain" rails project, and the same effect as before (webrick doesn't listen to 3000) happened.

So it seems, that for some projects, 3000 isn't active and for other projects, webrick listenes, but I get these errors (see picture) and cannot do a "c" or "n" or so.

It tried to use the port-version of vim instead of macvim, but the maintainer doesn't offer the client-server-option and enabling it manually would probably require to more or less understand the port building process.

If I can help you on a more systematical way to diagnose the problem i will gladly!

-- Frank

fwoeck commented 15 years ago

PS.: just for clarification: I think, in my environment, the same settings/code work under Ubuntu but probably newer worked under Osx (at least I can't remember)

fwoeck commented 15 years ago

arghh - I closed the issue - sorry - stupid me...

fwoeck commented 15 years ago

Hi Anton,

I created a quick screencast to show what I see under OsX. It's here: http://fwoeck00.s3.amazonaws.com/cap_vim_debugger.mov

I forgot to mention the version of mvim and the server mode: http://gist.github.com/140533

As I say at the end of the video, this behaviour is one of two possible failure modes. With some other rails-apps under OsX, webrick start up but doesn't listen to port 3000. The rest then is the same like showed in the screencast.

Hope it helps ;) -- Frank

astashov commented 15 years ago

This is just AMAZING!!! Cool movie, really, very helpful. I can wish everybody have such awesome bug reporter like you, thank you very much! :)

So, issue is happened somewhere between sending command to ruby_debugger.rb (intermediate ruby process, that sends commands ruby-debug-ide gem, receives commands from it and sends answer to Vim) and receiving the answer by Vim

After setting the breakpoint (at 06:17), you can see in logs (07:00), that breakpoint was created (string

'13:02:09 Set breakpoint to blablabla...'

), but answer from ruby_debugger.rb wasn't received (07:00, the top string -

'breakpointAdded no="1" .... index.erb:12'

should be changed to

'breakpointAdded .... welcome_controller.rb:5

)

There are 3 reasons of this issue:

  1. Vim doesn't send command to ruby-debugger.rb. You can check this by executing after :Rdebugger: echo has_key(g:RubyDebugger, 'server') && g:RubyDebugger.server.is_running() If result is equal to '1', then all works correctly.
  2. Ruby_debugger.rb doesn't work correctly (doesn't send command to ruby-debug-ide or doesn't receives command from it, or doesn't send received command to Vim).
  3. Sender to ruby_debugger.rb doesn't work correctly. You can try to change sender to ruby_debugger.rb to C-written program, that do the same thing, but works slightly faster. For this, copy "socket" file from additionals/bin/ to ~/.vim/bin/, add execution rights to it (chmod +x) and add this string to your .vimrc: let g:ruby_debugger_fast_sender = 1

    (you can read it in :help ruby-debugger-details)

Tell me about results, please! Thanks a lot! Especially thanks for such great screencast! :)

astashov commented 15 years ago

Also, can you try to run :Rdebugger two times? I mean: :Rdebugger :Rdebugger It should show something like this second time: Loading debugger... Killing server with pid 7463 Killing server with pid 7466 Debugger started

fwoeck commented 15 years ago

Glad, you enjoy it :)

so echo has_key(g:RubyDebugger, 'server') says 1 but echo g:RubyDebugger.server.is_running() says 0

when I say :Rdebugger more than once, the old pids are not killed, but simply more ruby-processes are spawned.

Activating "socket" didn't change this...

:RdbStop sometimes throws one of these errors, sometimes it says just "killing pid ..." but never actually kills any process.

astashov commented 15 years ago

Aha! Cool! Issue is: lsof doesn't work! Did you pull the latest version of the vim-ruby-debugger from the repo? Can you check ~/.vim/plugin/ruby_debugger.vim and look for function! s:Server._get_pid_attempt(port) and check string: let pid = system("lsof -i tcp:" . a:port . " | grep LISTEN | awk '{print $2}'") Does it look like this?

fwoeck commented 15 years ago

line #1468, yep it's there, but I have the impression that it really could have something to do with ip6.

I did:

$ sudo ip6 -d lo0

so that

$ analytics(master) > ifconfig lo0 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet 127.0.0.1 netmask 0xff000000

(usually ipv6 is active on all interfaces)

Now, when I say :Rdebugger,

:echo has_key(g:RubyDebugger, 'server') && g:RubyDebugger.server.is_running()

is 1(!), and :RdbStop kills the ruby-procs, BUT

webrick doesn't listen to :3000 anymore...

lsof -i tcp

ruby 809 fw 6u IPv4 0x9773270 0t0 TCP *:39767 (LISTEN) ruby 809 fw 7u IPv4 0x9791a68 0t0 TCP localhost:39767->localhost:49239 (ESTABLISHED) ruby 812 fw 6u IPv4 0x82e0e64 0t0 TCP localhost:49239->localhost:39767 (ESTABLISHED) ruby 812 fw 7u IPv4 0x976f66c 0t0 TCP localhost:39768 (LISTEN)

fwoeck commented 15 years ago

hmmm, following this

http://forums.aptana.com/viewtopic.php?p=22424

I changed

/opt/.../1.8/gems/ruby-debug-ide-0.nn/lib/ruby-debug.rb

... host = "0.0.0.0" ...

and line 42 of your ruby_debugger.vim to

let s:hostname = '0.0.0.0' "hostname()

AND of course, I turned off ipv6 on lo0:

sudo ip6 -d lo0

so NOW

a) lsof -i tcp

COMMAND    PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
ruby      1657   fw    6u  IPv4 0x9797a68      0t0  TCP *:39767 (LISTEN)
ruby      1657   fw    7u  IPv4 0x82e0e64      0t0  TCP localhost:39767->localhost:49479 (ESTABLISHED)
ruby      1657   fw   10u  IPv4 0x9747e64      0t0  TCP *:hbci (LISTEN)
ruby      1660   fw    6u  IPv4 0x977fe64      0t0  TCP localhost:49479->localhost:39767 (ESTABLISHED)
ruby      1660   fw    7u  IPv4 0x9782a68      0t0  TCP *:39768 (LISTEN)

and b)

echo has_key(g:RubyDebugger, 'server') && g:RubyDebugger.server.is_running()

says 1

and c)

:Rdebugger and :RdbStop works and when I

d) launch Firefox on http://127.0.0.1:3000 with a breakpoint set it stops AND I can

e) do a leader-c

BUT

f) I dont't see the red breakpoint-marker in macvim turn blue/grey and move

and g)

cat ruby_debugger_output

Fast Debugger (ruby-debug-ide 0.4.6) listens on 0.0.0.0:39767
=> Booting WEBrick
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-07-04 17:38:48] INFO  WEBrick 1.3.1
[2009-07-04 17:38:48] INFO  ruby 1.8.7 (2009-06-12) [i686-darwin9]
[2009-07-04 17:38:48] WARN  TCPServer Error: Can't assign requested address - bind(2)
[2009-07-04 17:38:48] INFO  WEBrick::HTTPServer#start: pid=1657 port=3000

Processing WelcomeController#index (for 127.0.0.1 at 2009-07-04 17:40:24) [GET]
Rendering template within layouts/application
Rendering welcome/index
Completed in 42393ms (View: 11, DB: 0) | 200 OK [http://127.0.0.1/]
astashov commented 15 years ago

Emm... I slightly didn't get this part :)

I dont't see the red breakpoint-marker in macvim turn blue/grey and move

So, what issues are still there now?

fwoeck commented 15 years ago

under Linux, when I set a breakpoint and I call Firefox and the Process reaches the breakpoint and I type leader-c or so, I see the red bar that marks the breakpoint moving accordingly to the next instruction.

In this case, the view in vim is not updated and the bar doesn't move and there are no variables displayed in the var-window (if open).

fwoeck commented 15 years ago

One addition: it seems, that in any case, when I enable the socket-ruby_debugger_fast_sender-option, the webrick server doesn't get startet on 3000 any more.

When I leave the option off, turn off ip6 and replace the above mentioned places by 0.0.0.0 or 127.0.0.1 (both work) it kind-of-works apart from the vim-view not beeing updated.

ouff, I take a break for today - will try some more tomorrow ;)

fwoeck commented 15 years ago

Hi Anton, thx again for the session!

I checked it - disabling ipv6 or changing "localhost" to "127.0.0.1" somewhere is not necessary. So it's sufficient to use "mvim" as progname.

Greetz, Frank

astashov commented 15 years ago

Ah, thanks. So, I can close the issue, can't I?

fwoeck commented 15 years ago

yes, I think, it's safe to close :)