Delve Dlv Not Restart When Update Files on Golang Cosmtrek Air 12710…

If you’re facing issues with Delve (dlv) not restarting when updating files in your Go project using Cosmtrek/Air version 1.27.10 and encountering a “port address already in use” error, there are a couple of solutions you can try. This problem often occurs due to lingering Delve processes that prevent the tool from restarting properly.

Solution 1: Revert to a Previous Version

You can revert to a previous version of Cosmtrek/Air where this issue might not exist. To do this, follow these steps:

  1. Open your terminal.

  2. Run the following command to install an earlier version (e.g., v1.27.4) of Cosmtrek/Air:

    1
    
    curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.4
  3. This will replace the current version of Cosmtrek/Air with the specified version (v1.27.4 in this case).

  4. After the installation is complete, try running your project again with the older version of Air to see if the issue is resolved.

Solution 2: Modify .air.toml to Kill Delve Processes

Another approach is to modify your .air.toml configuration to ensure that any lingering Delve processes are killed before starting a new one. Here’s how you can do it:

  1. Open your .air.toml file in a text editor.

  2. Locate the full_bin configuration in your .air.toml file. It should look something like this:

    1
    
    full_bin = "dlv exec --accept-multiclient --log --headless --continue --listen :2345 --api-version 2 ./tmp/main"
  3. Modify it to include the following command to kill any existing Delve (dlv) or main processes before starting a new one:

    1
    
    full_bin = "pkill -9 'dlv|main'; sleep 0.1; dlv exec --accept-multiclient --log --headless --continue --listen :2345 --api-version 2 ./tmp/main"

    This modification ensures that any existing Delve or main processes are forcefully terminated before attempting to start a new one.

  4. Save your .air.toml file.

  5. Try running your project with Air again to see if the issue is resolved. The modified configuration should now properly restart Delve.

By implementing one of these solutions, you should be able to resolve the issue of Delve not restarting when updating files in your Go project using Cosmtrek/Air 1.27.10.

0%