puremourning / vimspector

vimspector - A multi-language debugging system for Vim
http://puremourning.github.io/vimspector-web
Apache License 2.0
4.08k stars 171 forks source link

Debugger won't start after adding docker mount #862

Closed region-spotteR closed 3 months ago

region-spotteR commented 4 months ago

Description

I would like to use Vimspector in a new project which uses docker containers for debugging. I adapted the stuff in the simple_python until I could reproduce the issue (description below). The issue appeared after I added the mount command (-v ./:/code/app). Before that I added the remoteWorkDir-variable to the config and I think it was working. Since I added the mount, it doesn't go away even though I removed the mount, removed the volumes. It keeps having this issue with the header values.

Is it reproducible in vim?

Reproducible in Vim

Works with clean config?

Yes

Sample project works?

Reproducible with sample project

Minimal Reproduction

List of steps to reproduce:

  1. cd into /path/to/vimspector/support/test/python/simple_python
  2. add the following configuration to .vimspector.json:
    "docker-pytest": {
      "variables": {
        "remoteWorkDir": "/code",
        "filepath": "app/test_fastapi_example.py"
      },
      "adapter": "python-remote-docker",
      "remote-cmdLine": ["-m", "pytest", "${filepath}" ],
      "remote-request": "launch",
      "configuration": {
        "request": "attach",
        "module": "pytest",
        "type": "debugpy",
        "cwd": "${remoteWorkDir}",
        "args": [
          "$filepath"
        ],
        "pathMappings": [
          {
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${remoteWorkDir}"
          }
        ]
      }
    },
  3. create the file fastapi_example.py from the documentation here
  4. create the file test_fastapi_example.py from the documentation here
  5. overwrite the dockerfile with
    
    FROM python:3.11-slim

WORKDIR /code RUN mkdir /code/app | pip install --no-cache-dir --upgrade fastapi debugpy httpx pytest

ADD main.py /root/main.py

ADD fastapi_example.py /code/app/fastapi_example.py ADD test_fastapi_example.py /code/app/test_fastapi_example.py CMD ["fastapi", "run", "app/fastapi_example.py", "--port", "8765"]

6. Build the container with `docker build -t fastapi_example .`
7. Run `vim ---clean Nu /path/to/vimspector/support/minimal_vimrc test_fastapi_example`
8. Start the docker container with `docker run -p 8765:8765 --name fastapi_example -v ./:/code/app -d fastapi_example`
9. Set a breakpoint in line 1 and start vimspector with `call vimspector#Launch()`
10. choose the `docker-pytest` configuration and enter `fastapi_example` as a containerID

### Expected Behaviour

Start the debugger and pause at line 1

### Actual Behaviour

under `:messages` we find the following error:

Error detected while processing function 32__OnServerData: line 6: Traceback (most recent call last): File "", line 1, in File "/Users//Documents/repos/vimspector/python3/vimspector/debug_session.py", line 558, in OnChannelData self._connection.OnData( data ) File "/Users//Documents/repos/vimspector/python3/vimspector/debug_adapter_connection.py", line 183, in OnData self._ReadHeaders() File "/Users//Documents/repos/vimspector/python3/vimspector/debug_adapter_connection.py", line 223, in _ReadHeaders key, value = str( header_line, 'utf-8' ).split( ':', 1 ) ^^^^^^^^^^ ValueError: not enough values to unpack (expected 2, got 1) Channel closed


Recently I also get an `RuntimeError: Can't listen for client connections: [Errno 98] Address already in use`

### Additional information

_No response_

### Installation Type

Plugin Manager (git clone)

### Vimspector version

a021907c4137f533f198e4a7ef2b0b4d18235ed2

### Debug Info

`Vimspector not connected, start a debug session first`

### Log file

2024-05-14 08:11:28,398 - INFO - debug_session.py:226 - 0 - User requested start debug session with {} 2024-05-14 08:11:28,401 - DEBUG - debug_session.py:187 - 0 - Reading configurations from: None 2024-05-14 08:11:28,401 - DEBUG - debug_session.py:187 - 0 - Reading configurations from: /Users/moritzb/Documents/repos/vimspector/support/test/python/simple_python/.vimspector.json 2024-05-14 08:11:28,472 - DEBUG - debug_session.py:250 - 0 - Reading gadget config: /Users/moritzb/Documents/repos/vimspector/gadgets/macos/.gadgets.json 2024-05-14 08:11:28,472 - DEBUG - debug_session.py:250 - 0 - Reading gadget config: None 2024-05-14 08:11:34,682 - DEBUG - utils.py:633 - None - Returning filepath from the map for filepath with args () 2024-05-14 08:11:34,682 - DEBUG - utils.py:633 - None - Returning remoteWorkDir from the map for remoteWorkDir with args () 2024-05-14 08:11:34,682 - DEBUG - utils.py:633 - None - Returning filepath from the map for filepath with args () 2024-05-14 08:11:34,682 - DEBUG - utils.py:633 - None - Returning workspaceRoot from the map for workspaceRoot with args () 2024-05-14 08:11:34,682 - DEBUG - utils.py:633 - None - Returning remoteWorkDir from the map for remoteWorkDir with args () 2024-05-14 08:11:34,682 - DEBUG - utils.py:633 - None - Returning port from the map for port with args () 2024-05-14 08:11:35,465 - DEBUG - utils.py:714 - None - Value for ContainerID not set in ${ContainerID} (from ${ContainerID}): set to fastapi_example 2024-05-14 08:11:35,465 - DEBUG - utils.py:633 - None - Returning ContainerID from the map for ContainerID with args () 2024-05-14 08:11:35,465 - DEBUG - utils.py:633 - None - Returning port from the map for port with args () 2024-05-14 08:11:35,465 - INFO - debug_session.py:485 - 0 - Configuration: {"adapter": "python-remote-docker", "remote-cmdLine": ["-m", "pytest", "app/test_fastapi_example.py"], "remote-request": "launch", "configuration": {"request": "attach", "module": "pytest", "type": "debugpy", "cwd": "/code", "args": ["app/test_fastapi_example.py"], "pathMappings": [{"localRoot": "/Users/moritzb/Documents/repos/vimspector/support/test/python/simple_python", "remoteRoot": "/code"}]}} 2024-05-14 08:11:35,465 - INFO - debug_session.py:487 - 0 - Adapter: {"port": "8765", "launch": {"remote": {"container": "fastapi_example", "runCommand": ["python3", "-m", "debugpy", "--listen", "0.0.0.0:8765", "--wait-for-client", "%CMD%"]}, "delay": "5000m"}} 2024-05-14 08:11:35,466 - DEBUG - debug_session.py:1203 - 0 - min_width/height: 149/50, actual: 337/43 - result: horizontal 2024-05-14 08:11:35,477 - DEBUG - debug_session.py:1787 - 0 - LAUNCH! 2024-05-14 08:11:35,477 - DEBUG - debug_session.py:1657 - 0 - Running remote app: ['docker', 'exec', '-t', 'fastapi_example', 'python3', '-m', 'debugpy', '--listen', '0.0.0.0:8765', '--wait-for-client', '-m', 'pytest', 'app/test_fastapi_example.py'] 2024-05-14 08:11:40,488 - INFO - debug_session.py:1402 - 0 - Starting debug adapter with: {"port": "8765", "launch": {"remote": {"container": "fastapi_example", "runCommand": ["python3", "-m", "debugpy", "--listen", "0.0.0.0:8765", "--wait-for-client", "%CMD%"]}, "delay": "5000m"}} 2024-05-14 08:11:40,488 - DEBUG - debug_session.py:1421 - 0 - Connection Type: channel 2024-05-14 08:11:51,279 - ERROR - debug_session.py:1466 - 0 - Unable to start debug server 2024-05-14 08:11:51,280 - INFO - debug_session.py:509 - 0 - Failed to launch or attach to the debug adapter 2024-05-14 08:12:21,795 - DEBUG - debug_session.py:620 - 0 - Stop debug adapter with callback: _Reset 2024-05-14 08:12:21,796 - INFO - debug_session.py:662 - 0 - Debugging complete. 2024-05-14 08:12:21,796 - DEBUG - debug_session.py:665 - 0 - Clearing down UI 2024-05-14 08:12:23,730 - INFO - debug_session.py:226 - 0 - User requested start debug session with {} 2024-05-14 08:12:23,731 - DEBUG - debug_session.py:187 - 0 - Reading configurations from: None 2024-05-14 08:12:23,732 - DEBUG - debug_session.py:187 - 0 - Reading configurations from: /Users/moritzb/Documents/repos/vimspector/support/test/python/simple_python/.vimspector.json 2024-05-14 08:12:23,807 - DEBUG - debug_session.py:250 - 0 - Reading gadget config: /Users/moritzb/Documents/repos/vimspector/gadgets/macos/.gadgets.json 2024-05-14 08:12:23,807 - DEBUG - debug_session.py:250 - 0 - Reading gadget config: None 2024-05-14 08:12:26,970 - DEBUG - utils.py:633 - None - Returning filepath from the map for filepath with args () 2024-05-14 08:12:26,971 - DEBUG - utils.py:633 - None - Returning remoteWorkDir from the map for remoteWorkDir with args () 2024-05-14 08:12:26,971 - DEBUG - utils.py:633 - None - Returning filepath from the map for filepath with args () 2024-05-14 08:12:26,971 - DEBUG - utils.py:633 - None - Returning workspaceRoot from the map for workspaceRoot with args () 2024-05-14 08:12:26,971 - DEBUG - utils.py:633 - None - Returning remoteWorkDir from the map for remoteWorkDir with args () 2024-05-14 08:12:26,971 - DEBUG - utils.py:633 - None - Returning port from the map for port with args () 2024-05-14 08:12:28,206 - DEBUG - utils.py:714 - None - Value for ContainerID not set in ${ContainerID} (from ${ContainerID}): set to fastapi_example 2024-05-14 08:12:28,206 - DEBUG - utils.py:633 - None - Returning ContainerID from the map for ContainerID with args () 2024-05-14 08:12:28,206 - DEBUG - utils.py:633 - None - Returning port from the map for port with args () 2024-05-14 08:12:28,207 - INFO - debug_session.py:485 - 0 - Configuration: {"adapter": "python-remote-docker", "remote-cmdLine": ["-m", "pytest", "app/test_fastapi_example.py"], "remote-request": "launch", "configuration": {"request": "attach", "module": "pytest", "type": "debugpy", "cwd": "/code", "args": ["app/test_fastapi_example.py"], "pathMappings": [{"localRoot": "/Users/moritzb/Documents/repos/vimspector/support/test/python/simple_python", "remoteRoot": "/code"}]}} 2024-05-14 08:12:28,207 - INFO - debug_session.py:487 - 0 - Adapter: {"port": "8765", "launch": {"remote": {"container": "fastapi_example", "runCommand": ["python3", "-m", "debugpy", "--listen", "0.0.0.0:8765", "--wait-for-client", "%CMD%"]}, "delay": "5000m"}} 2024-05-14 08:12:28,208 - DEBUG - debug_session.py:1203 - 0 - min_width/height: 149/50, actual: 337/43 - result: horizontal 2024-05-14 08:12:28,223 - DEBUG - debug_session.py:1787 - 0 - LAUNCH! 2024-05-14 08:12:28,223 - DEBUG - debug_session.py:1657 - 0 - Running remote app: ['docker', 'exec', '-t', 'fastapi_example', 'python3', '-m', 'debugpy', '--listen', '0.0.0.0:8765', '--wait-for-client', '-m', 'pytest', 'app/test_fastapi_example.py'] 2024-05-14 08:12:33,235 - INFO - debug_session.py:1402 - 0 - Starting debug adapter with: {"port": "8765", "launch": {"remote": {"container": "fastapi_example", "runCommand": ["python3", "-m", "debugpy", "--listen", "0.0.0.0:8765", "--wait-for-client", "%CMD%"]}, "delay": "5000m"}} 2024-05-14 08:12:33,235 - DEBUG - debug_session.py:1421 - 0 - Connection Type: channel 2024-05-14 08:12:44,022 - ERROR - debug_session.py:1466 - 0 - Unable to start debug server 2024-05-14 08:12:44,022 - INFO - debug_session.py:509 - 0 - Failed to launch or attach to the debug adapter 2024-05-14 08:14:00,337 - DEBUG - debug_session.py:620 - 0 - Stop debug adapter with callback: _Reset 2024-05-14 08:14:00,338 - INFO - debug_session.py:662 - 0 - Debugging complete. 2024-05-14 08:14:00,338 - DEBUG - debug_session.py:665 - 0 - Clearing down UI


### Vim version

```Text
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan 04 2024 03:00:35)
macOS version - arm64
Compiled by Homebrew
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +find_in_path      +mouse_xterm       +tcl
+arabic            +float             +multi_byte        +termguicolors
+autocmd           +folding           +multi_lang        +terminal
+autochdir         -footer            -mzscheme          +terminfo
-autoservername    +fork()            +netbeans_intg     +termresponse
+balloon_eval      +fullscreen        +num64             +textobjects
+balloon_eval_term +gettext           +odbeditor         +textprop
+browse            -hangul_input      +packages          +timers
++builtin_terms    +iconv             +path_extra        +title
+byte_offset       +insert_expand     +perl              +toolbar
+channel           +ipv6              +persistent_undo   +transparency
+cindent           +job               +popupwin          +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3           +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby              +wildignore
+cursorbind        +lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con_gui    +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             +sound             -xattr
+dnd               +mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       +xim
+emacs_tags        -mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static
+file_in_path      +mouse_urxvt       -tag_any_white
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_DARWIN -g -O2 -arch arm64 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -arch arm64 -L/opt/homebrew/lib -o Vim -lm -lncurses /opt/homebrew/lib/libsodium.a -liconv /opt/homebrew/lib/libintl.a -framework AppKit -L/opt/homebrew/opt/lua/lib -llua5.4 -L/System/Library/Perl/5.34/darwin-thread-multi-2level/CORE -lperl -L/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin -lpython3.12 -framework CoreFoundation -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -lruby.3.3 -L/opt/homebrew/Cellar/ruby/3.3.0/lib

Python version

No response

Neovim diagnostics

No response

Operating System

MacOs

Declaration

puremourning commented 3 months ago

2 issues :

  1. port 8765 seems to be in use in the container, switch to 8764 for the debugpy port
  2. fix path mappings
{
  "$schema": "https://puremourning.github.io/vimspector/schema/vimspector.schema.json",
  "adapters": {
    "python-remote-docker": {
      "variables": {
        "port": "8764"
      },
      "port": "${port}",
      "launch": {
        "remote": {
          "container": "${ContainerID}",
          "runCommand": [
            "python3", "-m", "debugpy", "--listen", "0.0.0.0:${port}",
                                        "--wait-for-client",
                                        "%CMD%"
          ]
        },
        "delay": "5000m"
      }
    }
  },
  "configurations":  {
    "docker-pytest": {
      "variables": {
        "remoteWorkDir": "/code/app",
        "filepath": "test_fastapi_example.py"
      },
      "adapter": "python-remote-docker",
      "remote-cmdLine": ["-m", "pytest", "${remoteWorkDir}/${filepath}" ],
      "remote-request": "launch",
      "configuration": {
        "request": "attach",
        "pathMappings": [
          {
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${remoteWorkDir}"
          }
        ]
      }
    }
  }
}