Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Debug with attach will terminate remote process when detach #2592

Closed

Description

I believe this PR #2125 suppose to support attaching and detaching from remote debug server without killing the process. However, when I host the GO process with delve in a docker, the remote debug process still killed the remote process.
Here is my vs code launch.json:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach: Debug users service",
      "type": "go",
      "request": "attach",
      "mode": "remote",
      "remotePath": "/go/src/app",
      "cwd":"${workspaceFolder}/users",
      "port": 2345,
      "host": "127.0.0.1",
      // "debugServer": 4711,
      "apiVersion": 2
    }
  ]
}

delve is running with:

/go/bin/dlv debug /go/src/cmd/server --accept-multiclient -l 0.0.0.0:2345 --headless=true --log --log-output debugger,rpc --api-version=2 

And the delve log:

Recreating bc-system-go_users_1 ... done
Attaching to bc-system-go_users_1
users_1  | API server listening at: [::]:2345
users_1  | time="2019-06-22T05:36:27Z" level=info msg="launching process with args: [/go/src/app/debug]" layer=debugger
users_1  | time="2019-06-22T05:36:31Z" level=debug msg="<- RPCServer.GetVersion(api.GetVersionIn{})" layer=rpc
users_1  | time="2019-06-22T05:36:31Z" level=debug msg="-> *api.GetVersionOut{\"DelveVersion\":\"Version: 1.2.0\\nBuild: $Id: 068e2451004e95d0b042e5257e34f0f08ce01466 $\",\"APIVersion\":2} error: \"\"" layer=rpc
users_1  | time="2019-06-22T05:36:31Z" level=debug msg="<- RPCServer.CreateBreakpoint(rpc2.CreateBreakpointIn{\"Breakpoint\":{\"id\":0,\"name\":\"\",\"addr\":0,\"file\":\"/go/src/app/main.go\",\"line\":8,\"Cond\":\"\",\"continue\":false,\"traceReturn\":false,\"goroutine\":false,\"stacktrace\":0,\"LoadArgs\":null,\"LoadLocals\":null,\"hitCount\":null,\"totalHitCount\":0}})" layer=rpc
users_1  | time="2019-06-22T05:36:31Z" level=info msg="created breakpoint: &api.Breakpoint{ID:1, Name:\"\", Addr:0xb597a1, File:\"/go/src/app/main.go\", Line:8, FunctionName:\"main.main.func1\", Cond:\"\", Tracepoint:false, TraceReturn:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(nil), LoadLocals:(*api.LoadConfig)(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0}" layer=debugger
users_1  | time="2019-06-22T05:36:31Z" level=debug msg="-> *rpc2.CreateBreakpointOut{\"Breakpoint\":{\"id\":1,\"name\":\"\",\"addr\":11900833,\"file\":\"/go/src/app/main.go\",\"line\":8,\"functionName\":\"main.main.func1\",\"Cond\":\"\",\"continue\":false,\"traceReturn\":false,\"goroutine\":false,\"stacktrace\":0,\"LoadArgs\":null,\"LoadLocals\":null,\"hitCount\":{},\"totalHitCount\":0}} error: \"\"" layer=rpc
users_1  | time="2019-06-22T05:36:31Z" level=debug msg="(async 3) <- RPCServer.Command(api.DebuggerCommand{\"name\":\"continue\",\"ReturnInfoLoadConfig\":null})" layer=rpc
users_1  | time="2019-06-22T05:36:31Z" level=debug msg=continuing layer=debugger
users_1  | [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
users_1  | 
users_1  | [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
users_1  |  - using env:        export GIN_MODE=release
users_1  |  - using code:       gin.SetMode(gin.ReleaseMode)
users_1  | 
users_1  | [GIN-debug] GET    /ping                     --> main.main.func1 (3 handlers)
users_1  | [GIN-debug] Environment variable PORT="8000"
users_1  | [GIN-debug] Listening and serving HTTP on :8000
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="(async 4) <- RPCServer.Command(api.DebuggerCommand{\"name\":\"halt\",\"ReturnInfoLoadConfig\":null})" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg=halting layer=debugger
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="(async 3) -> rpc2.CommandOut{\"State\":{\"Running\":false,\"currentThread\":{\"id\":1304,\"pc\":4602944,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":675,\"function\":{\"name\":\"runtime.epollwait\",\"value\":4602912,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},\"Threads\":[{\"id\":1310,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1311,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1312,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1304,\"pc\":4602944,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":675,\"function\":{\"name\":\"runtime.epollwait\",\"value\":4602912,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1307,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1308,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1309,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null}],\"NextInProgress\":false,\"exited\":false,\"exitStatus\":0,\"When\":\"\"}} error: \"\"" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="<- RPCServer.ListGoroutines(rpc2.ListGoroutinesIn{\"Start\":0,\"Count\":0})" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="(async 4) -> rpc2.CommandOut{\"State\":{\"Running\":false,\"currentThread\":{\"id\":1304,\"pc\":4602944,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":675,\"function\":{\"name\":\"runtime.epollwait\",\"value\":4602912,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},\"Threads\":[{\"id\":1308,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1309,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1310,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1311,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1312,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1304,\"pc\":4602944,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":675,\"function\":{\"name\":\"runtime.epollwait\",\"value\":4602912,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null},{\"id\":1307,\"pc\":4602515,\"file\":\"/usr/local/go/src/runtime/sys_linux_amd64.s\",\"line\":536,\"function\":{\"name\":\"runtime.futex\",\"value\":4602480,\"type\":0,\"goType\":0,\"optimized\":true},\"goroutineID\":0,\"ReturnValues\":null}],\"NextInProgress\":false,\"exited\":false,\"exitStatus\":0,\"When\":\"\"}} error: \"\"" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="-> *rpc2.ListGoroutinesOut{\"Goroutines\":[{\"id\":1,\"currentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"userCurrentLoc\":{\"pc\":4387310,\"file\":\"/usr/local/go/src/runtime/netpoll.go\",\"line\":182,\"function\":{\"name\":\"internal/poll.runtime_pollWait\",\"value\":4387216,\"type\":0,\"goType\":0,\"optimized\":true}},\"goStatementLoc\":{\"pc\":4586089,\"file\":\"/usr/local/go/src/runtime/asm_amd64.s\",\"line\":201,\"function\":{\"name\":\"runtime.rt0_go\",\"value\":4585792,\"type\":0,\"goType\":0,\"optimized\":true}},\"startLoc\":{\"pc\":4408848,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":110,\"function\":{\"name\":\"runtime.main\",\"value\":4408848,\"type\":0,\"goType\":0,\"optimized\":true}},\"threadID\":0,\"unreadable\":\"\"},{\"id\":2,\"currentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"userCurrentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"goStatementLoc\":{\"pc\":4409701,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":239,\"function\":{\"name\":\"runtime.init.5\",\"value\":4409648,\"type\":0,\"goType\":0,\"optimized\":true}},\"startLoc\":{\"pc\":4409728,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":242,\"function\":{\"name\":\"runtime.forcegchelper\",\"value\":4409728,\"type\":0,\"goType\":0,\"optimized\":true}},\"threadID\":0,\"unreadable\":\"\"},{\"id\":18,\"currentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"userCurrentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"goStatementLoc\":{\"pc\":4320424,\"file\":\"/usr/local/go/src/runtime/mgc.go\",\"line\":208,\"function\":{\"name\":\"runtime.gcenable\",\"value\":4320336,\"type\":0,\"goType\":0,\"optimized\":true}},\"startLoc\":{\"pc\":4353568,\"file\":\"/usr/local/go/src/runtime/mgcsweep.go\",\"line\":64,\"function\":{\"name\":\"runtime.bgsweep\",\"value\":4353568,\"type\":0,\"goType\":0,\"optimized\":true}},\"threadID\":0,\"unreadable\":\"\"},{\"id\":19,\"currentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"userCurrentLoc\":{\"pc\":4410276,\"file\":\"/usr/local/go/src/runtime/proc.go\",\"line\":302,\"function\":{\"name\":\"runtime.gopark\",\"value\":4410064,\"type\":0,\"goType\":0,\"optimized\":true}},\"goStatementLoc\":{\"pc\":4316193,\"file\":\"/usr/local/go/src/runtime/mfinal.go\",\"line\":156,\"function\":{\"name\":\"runtime.createfing\",\"value\":4316096,\"type\":0,\"goType\":0,\"optimized\":true}},\"startLoc\":{\"pc\":4316208,\"file\":\"/usr/local/go/src/runtime/mfinal.go\",\"line\":161,\"function\":{\"name\":\"runtime.runfinq\",\"value\":4316208,\"type\":0,\"goType\":0,\"optimized\":true}},\"threadID\":0,\"unreadable\":\"\"}],\"Nextg\":-1} error: \"\"" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="<- RPCServer.Detach(rpc2.DetachIn{\"Kill\":false})" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="-> *rpc2.DetachOut{} error: \"\"" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="<- RPCServer.ListGoroutines(rpc2.ListGoroutinesIn{\"Start\":0,\"Count\":0})" layer=rpc
users_1  | time="2019-06-22T05:36:38Z" level=debug msg="-> *rpc2.ListGoroutinesOut{\"Goroutines\":null,\"Nextg\":0} error: \"Process 1304 has exited with status 0\"" layer=rpc
users_1  | time="2019-06-22T05:36:39Z" level=debug msg="<- RPCServer.ListGoroutines(rpc2.ListGoroutinesIn{\"Start\":0,\"Count\":0})" layer=rpc
users_1  | time="2019-06-22T05:36:39Z" level=debug msg="-> *rpc2.ListGoroutinesOut{\"Goroutines\":null,\"Nextg\":0} error: \"Process 1304 has exited with status 0\"" layer=rpc
bc-system-go_users_1 exited with code 0

Originally I think this should be a bug in delve so I created issue go-delve/delve#1587 . However, they mentioned in the comment(go-delve/delve#1587 (comment)) that detach will terminate the debugger process and what should happen is resume the process and then disconnect.

Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions