douzhicong5965 2018-11-09 01:11
浏览 123
已采纳

dlv seg在高山docker容器内部故障

I am running dlv inside alpine:3.7.1 container. It is crashing with this error:

/ # /dlv --listen=:40000 --headless=true --api-version=2 exec /server
Could not create config directory: user: Current not implemented on linux/amd64.panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x8c7dca]

goroutine 1 [running]:
github.com/derekparker/delve/cmd/dlv/cmds.execute(0x0, 0xc420057a00, 0x1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0)
        /go/src/github.com/derekparker/delve/cmd/dlv/cmds/commands.go:575 +0x3aa
github.com/derekparker/delve/cmd/dlv/cmds.New.func4(0xc42014a000, 0xc420057a00, 0x1, 0x4)
        /go/src/github.com/derekparker/delve/cmd/dlv/cmds/commands.go:182 +0x65
github.com/derekparker/delve/vendor/github.com/spf13/cobra.(*Command).execute(0xc42014a000, 0xc42001c6c0, 0x4, 0x6, 0xc42014a000, 0xc42001c6c0)
        /go/src/github.com/derekparker/delve/vendor/github.com/spf13/cobra/command.go:647 +0x237
github.com/derekparker/delve/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc4200d1680, 0xc4200d1d40, 0xc4200d1b00, 0xc4200d18c0)
        /go/src/github.com/derekparker/delve/vendor/github.com/spf13/cobra/command.go:733 +0x2d4
github.com/derekparker/delve/vendor/github.com/spf13/cobra.(*Command).Execute(0xc4200d1680, 0xc4200d1680, 0x9fad07)
        /go/src/github.com/derekparker/delve/vendor/github.com/spf13/cobra/command.go:692 +0x2b
main.main()
        /go/src/github.com/derekparker/delve/cmd/dlv/main.go:24 +0xe4

My Dockerfile:

# Compile stage
FROM golang:1.10.1-alpine3.7 AS build-env
ENV CGO_ENABLED 0
ADD . /go/src/hello

# The -gcflags "all=-N -l" flag helps us get a better debug experience
#RUN go build -x -gcflags "all=-N -l" -o /server hello
RUN go build -gcflags "all=-N -l" -o /server hello

# Compile Delve
RUN apk add --no-cache git
RUN go get github.com/derekparker/delve/cmd/dlv

# Final stage
FROM alpine:3.7

# Port 8080 belongs to our application, 40000 belongs to Delve
EXPOSE 8080 40000

# Allow delve to run on Alpine based containers.
RUN apk add --no-cache libc6-compat

WORKDIR /

COPY --from=build-env /server /
COPY --from=build-env /go/bin/dlv /

# Run delve
#CMD ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "exec", "/server"]
#/dlv --listen=:40000 --headless=true --api-version=2 exec /server

CMD ["/bin/sh"]

I am running the container as:

$ docker run -p 8080:8080 -p 40000:40000 --name hello-go-delve3 --cap-add SYS_PTRACE --security-opt apparmor=unconfined

The server starts up fine and services requests if I run it without delve.

# /server
2018/11/09 01:13:18 starting server...

Some additional debugging if it helps is below.

# /dlv version
Could not create config directory: user: Current not implemented on  linux/amd64.Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $

# uname -a
Linux 168365401d8d 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 Linux

# cat /etc/alpine-release 
3.7.1

I get similar segfault from /dlv if I run /server in the background and then attach to it from /dlv:

# /server &
2018/11/09 01:25:02 starting server...

# ps
PID   USER     TIME   COMMAND
    1 root       0:00 /bin/sh
   21 root       0:00 /server
   24 root       0:00 ps

# /dlv --listen=:40000 --headless=true --api-version=2 attach 21
Could not create config directory: user: Current not implemented on linux/amd64.panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x8c7dca]

goroutine 1 [running]:
github.com/derekparker/delve/cmd/dlv/cmds.execute(0x15, 0xc420057a50, 0x0, 0x3, 0x0, 0x0, 0x0, 0x3, 0x0)
        /go/src/github.com/derekparker/delve/cmd/dlv/cmds/commands.go:575 +0x3aa
github.com/derekparker/delve/cmd/dlv/cmds.attachCmd(0xc4200d18c0, 0xc420057a40, 0x1, 0x4)
        /go/src/github.com/derekparker/delve/cmd/dlv/cmds/commands.go:469 +0xc2
github.com/derekparker/delve/vendor/github.com/spf13/cobra.(*Command).execute(0xc4200d18c0, 0xc42001c660, 0x4, 0x6, 0xc4200d18c0, 0xc42001c660)
        /go/src/github.com/derekparker/delve/vendor/github.com/spf13/cobra/command.go:647 +0x237
github.com/derekparker/delve/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc4200d1680, 0xc4200d1d40, 0xc4200d1b00, 0xc4200d18c0)
        /go/src/github.com/derekparker/delve/vendor/github.com/spf13/cobra/command.go:733 +0x2d4
github.com/derekparker/delve/vendor/github.com/spf13/cobra.(*Command).Execute(0xc4200d1680, 0xc4200d1680, 0x9fad07)
        /go/src/github.com/derekparker/delve/vendor/github.com/spf13/cobra/command.go:692 +0x2b
main.main()
        /go/src/github.com/derekparker/delve/cmd/dlv/main.go:24 +0xe4

It was running fine earlier today. Not sure what I changed. Any pointers would be helpful. Thank you.

  • 写回答

1条回答 默认 最新

  • 普通网友 2018-11-09 02:41
    关注

    If I change

    FROM golang:1.10.1-alpine3.7 AS build-env
    

    to

    FROM golang:1.10-alpine3.7 AS build-env
    

    /dlv starts working fine and doesn't crash anymore.

    I think this change ensures that the build container is the same the runtime container.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算