delve: stub exited while waiting for connection: exit status 0

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output, stacktraces, etc) as linked gists.

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 1.3.0
Build: $Id: 2f59bfc686d60989dcef9de40b480d0a34aa2fa5 $
  1. What version of Go are you using? (go version)? go version go1.13.1 darwin/amd64```

  2. What operating system and processor architecture are you using? mac osX 10.14.6

  3. What did you do? When I attached a process in GoLand the first time it worked fine and after some time its started failing with error below. Then I used the command line dlv command dlv attach <pid> and its giving the same error.

  4. What did you expect to see?

  5. What did you see instead?

GOLAND error

API server listening at: 127.0.0.1:50393
could not attach to pid 28780: stub exited while waiting for connection: exit status 0

Debugger finished with exit code 1```

CMD line error 
```could not attach to pid 28780: stub exited while waiting for connection: exit status 0```



I have checked my hosts file and it looks fine. I am not sure what went wrong since its worked the first time and not it doesnt. 

Please help

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (6 by maintainers)

Most upvoted comments

For anyone else that may run into this: If you’re on an M1 Mac, make sure you have the arm64 version of VS Code installed - that fixed it for me.

I just ran into this and fixed by running:

$ sudo /usr/sbin/DevToolsSecurity --enable

For whomever stumbles upon this thread:

This is due to a MacOS restriction. taskgated (Gatekeeper) checks for an entitlement com.apple.security.get-task-allow to attach the debugger. You can observe the relevant logs in Console.app for the processes (taskgated, debugserver, and kernel).

I was able to resolve this issue for me by running dlv attach... with sudo.

Or if you cannot run dlv as root (i.e. you really want to clicky attach in GoLand):

  1. Create a code signing certificate with Keychain Access
  2. Create an entitlements.plist file containing:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
         <key>com.apple.security.get-task-allow</key>
         <true/>
</dict>
</plist>
  1. Notarize your executable (must be done after every build):
codesign -fs <certificate name> --timestamp --options=runtime --entitlements entitlements.plist $GOPATH/bin/<executable>
  1. Attach dlv to the process.

TL;DR: Run dlv attach with sudo.

P.S Like the OP, I was also able to attach Delve on the initial attempt. It was probably allowed due to a bug. I was able to do it again one time after disabling SIP(csrutil disable).

P.P.S. There’s probably another way to get this running easily in GoLand. Maybe renaming /Applications/GoLand.app/Contents/plugins/go/lib/dlv/mac/dlv and replacing it with a script named dlv that calls the former dlv with sudo and passes the args. OR, maybe I’ll open an issue with JetBrains.

I just ran into this and fixed by running:

$ sudo /usr/sbin/DevToolsSecurity --enable

Fixed my issues with remote dev setup on a M1 Pro 🥳

@matthewhembree what PID am I attaching delve to? I am running into this issue in VSCode.

@AndrewRPorter The PID will be of your application that you want to debug.

OT: I’ve found it difficult to do serious debugging with VSCode. The inspector couldn’t handle large structs. It wouldn’t show the values hierarchically and it would truncate large structs. If VSCode meets your needs, then stick with it. VSCode is less demanding on resources, so that’s a plus.

@hilaily it should work without sudo. Please check if running the following command helps:

sudo dscl . append /Groups/_developer GroupMembership <your username>