【问题标题】:GO script runtime error for Amazon AWS S3Amazon AWS S3 的 GO 脚本运行时错误
【发布时间】:2016-07-25 17:35:59
【问题描述】:

我目前正在尝试在 Amazon Linux Distro 上首次运行以下 Golang 构建:

https://github.com/adammck/s3-graphite

这里是自述文件:

go get github.com/adammck/s3-graphite
cd $GOPATH/adammck/s3-graphite
go build

在此之后,我在 .bashrc 文件中设置变量,如下所示:

# AWS keys with read access to the bucket
export AWS_ACCESS_KEY_ID=xxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=yyyyyyyyyy
export AWS_REGION=us-east-1

# the bucket to watch
export S3_BUCKET=my-bucket
export S3_PREFIX=dir/subdir

# the server to send metrics to
export GRAPHITE_ADDRESS=metrics.example.com
export GRAPHITE_PREFIX=s3-count.my-bucket.dir.subdir

我将我的 GOPATH 设置为:

export GOPATH="$HOME/work/"

我 cd 进入目录运行一个 go build,它应该像它应该的那样工作,但是当我在 go build 之后运行以下内容时:

./s3-石墨

我收到以下错误:

INFO[0000] Starting s3-graphite...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x4e3256]

goroutine 1 [running]:
github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)
    /home/ec2-user/work/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x76
main.NewS3(0x7ffc202bef6e, 0x1b, 0x7ffc202be684, 0x9, 0x1, 0x0, 0x0)
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/s3.go:20 +0x66
main.main()
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/main.go:19 +0x21c

goroutine 2 [runnable]:
runtime.forcegchelper()
    /usr/lib/golang/src/runtime/proc.go:90
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:2232 +0x1

goroutine 3 [runnable]:
runtime.bgsweep()
    /usr/lib/golang/src/runtime/mgc0.go:82
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:2232 +0x1

goroutine 4 [runnable]:
runtime.runfinq()
    /usr/lib/golang/src/runtime/malloc.go:712
runtime.goexit()
    /usr/lib/golang/src/runtime/asm_amd64.s:2232 +0x1

这是我的 GOPATH:

$GOPATH
-bash: /home/ec2-user/work/: Is a directory

这是我执行 s3-graphite 的目录:

/home/ec2-user/work/src/github.com/adammck/s3-graphite

编辑(使用您的回答中的项目更新:

[ec2-user@s3-graphite]$ go version
go version go1.6.3 linux/amd64
[ec2-user@ s3-graphite]$ $GOPATH
-bash: /home/ec2-user/work: Is a directory
[ec2-user@ s3-graphite]$ pwd
/home/ec2-user/work/src/github.com/adammck/s3-graphite
[ec2-user@ s3-graphite]$ ./s3-graphite
INFO[0000] Starting s3-graphite...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x512aa2]

goroutine 1 [running]:
panic(0x873120, 0xc82000a0e0)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)
    /home/ec2-user/work/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x72
main.NewS3(0xc82001603a, 0x1b, 0xc82000e06a, 0x9, 0x1, 0x0, 0x0)
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/s3.go:20 +0x4a
main.main()
    /home/ec2-user/work/src/github.com/adammck/s3-graphite/main.go:19 +0x229
[ec2-user@ s3-graphite]$

【问题讨论】:

    标签: amazon-web-services github go amazon-s3 runtime-error


    【解决方案1】:

    这里似乎发生了一些事情。要检查的一件事是,在其中设置环境变量后,您实际上是在采购 .bashrc 文件。您应该能够运行 env 命令并在当前 shell 中查看您的 AWS 密钥、S3 配置和石墨设置。

    我看到的第二个问题是您使用的库自去年以来一直没有更新。据我所知,AWS SDK for Go 在过去一年发生了很大变化。应用程序输出中的“panic:”行给出了问题的提示。

    恐慌:运行时错误:无效的内存地址或 nil 指针取消引用

    似乎nil 被传递到不应该传递的地方。进一步向下恐慌输出,您可以看到 goroutine 1 的堆栈跟踪说:

    github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)
        /home/ec2-user/work/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x76
    main.NewS3(0x7ffc202bef6e, 0x1b, 0x7ffc202be684, 0x9, 0x1, 0x0, 0x0)
        /home/ec2-user/work/src/github.com/adammck/s3-graphite/s3.go:20 +0x66
    

    从这里你可以看到在 s3-graphite 库中的 s3.go 文件的第 20 行调用了 NewS3 方法。然后它转到 aws-sdk-go 库并尝试创建一个新的 S3 客户端。使用以下参数:

    s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x3f)

    最好的办法是您的配置没有导出到您运行可执行文件的环境中,或者需要更新 s3-graphite 库以使用最新的 aws-sdk-go 版本。

    【讨论】:

    • 感谢您的回复。我更新了 GO 版本并确保让 $GOPATH 与使用我需要的数据采购 .bashrc 文件一起工作,但这仍然是不行的。请在主帖中查看上面的编辑。 @rking788
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 2020-12-11
    • 2016-08-08
    相关资源
    最近更新 更多