Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAP Couldn't connect to 127.0.0.1:54701: ECONNREFUSED #33

Open
kayn1 opened this issue May 6, 2024 · 4 comments
Open

DAP Couldn't connect to 127.0.0.1:54701: ECONNREFUSED #33

kayn1 opened this issue May 6, 2024 · 4 comments

Comments

@kayn1
Copy link

kayn1 commented May 6, 2024

What?

This plugin does not seem to work. It fails everytime.

DAP Couldn't connect to 127.0.0.1:54701: ECONNREFUSED

Port does not make any difference here.

Steps to reproduce:

  1. Create test file with rspec
  2. Put breakpoint somewhere
  3. Run debug current file or whatever.

Also, I can't add my own configuration so this is also an issue.

      local dap = require("dap")
      require("dap-ruby").setup()
      dap.configurations.ruby = {
        {
          type = "ruby",
          name = "debug rspec line",
          bundle = "bundle",
          request = "attach",
          command = "rspec",
          script = "${file}",
          port = 38698,
          server = "127.0.0.1",
          options = {
            source_filetype = "ruby",
          },
          localfs = true,
          waiting = 1000,
          current_line = true,
        },
        {
          type = "ruby",
          name = "debug rspec file",
          bundle = "bundle",
          request = "attach",
          command = "rspec",
          script = "${file}",
          port = 38698,
          server = "127.0.0.1",
          options = {
            source_filetype = "ruby",
          },
          localfs = true,
          waiting = 1000,
        },

I see that some other people reported this.

@tttffff
Copy link
Contributor

tttffff commented May 7, 2024

The debug gem needs to be installed for your system or for your project if you have a Gemfile. This is what is talking DAP to Neovim. gem install debug for system or bundle add debug to add to a projects Gemfile. If adding to a project/Gemfile, it probably wants to be in the development and test environments only.

To test, open a terminal and cd to your project, then run:

RUBY_DEBUG_OPEN=true RUBY_DEBUG_HOST="127.0.0.1" RUBY_DEBUG_PORT=54701 bundle exec rspec PATH_TO_SPEC_FILE

Where PATH_TO_SPEC_FILE might be spec/test_spec.rb. You should see DEBUGGER: Debugger can attach via TCP/IP (127.0.0.1:54701) near the top of stdout after running the command. If not, then that will explain the ECONNREFUSED.

We have a project that did use byebug for debuging, but it doesn't have remote debugging AFAIK so we've moved to debug. The debug gem is what's suggested now for Ruby 3. I'm guessing the issue you've experienced is similar.

@kayn1
Copy link
Author

kayn1 commented May 7, 2024

@tttffff Thanks for your reply. I am trying to make this work but without success.
I did what you said.
Screenshot 2024-05-07 at 21 03 38
Screenshot 2024-05-07 at 21 04 14
Screenshot 2024-05-07 at 21 03 47
Screenshot 2024-05-07 at 21 03 47 2
Screenshot 2024-05-07 at 21 03 44

None of this does not work for me.
This is a test repo I've used for testing

@BaronBonet
Copy link

BaronBonet commented May 18, 2024

@kayn1 I ran into a similar issue, asked a question on reddit and got this answer which worked.

The below two functions are respectively working for debugging ruby files and test files.

local function start_ruby_debugger()
  vim.fn.setenv("RUBYOPT", "-rdebug/open")
  require("dap").continue()
end

local function start_rspec_debugger()
  vim.fn.setenv("RUBYOPT", "-rdebug/open")
  require("dap").run({
    type = "ruby",
    name = "debug rspec file",
    request = "attach",
    command = "rspec",
    script = "${file}",
    port = 38698,
    server = "127.0.0.1",
    localfs = true, -- required to be able to set breakpoints locally
    stopOnEntry = false, -- This has no effect
  })
end

The secret sauce is setting RUBYOPT="-rdebug/open" in your environment.

At the moment, whenever I debug a ruby file or a test file the debugger stops at the 1st line, the stopOnEntry flag does not seem to have an effect, then I have to run continue so it hits my breakpoint. This is a bit annoying but not a show stopper so I'm going to move on for now.

I'm curious if this solves your issue.

@kayn1
Copy link
Author

kayn1 commented May 25, 2024

Nope, this did not work for me. How to extend the default configuration from this gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants