【遇到一个神奇的问题】暂未想到原因,http.Post 传入 nil参数正确,但是传输值为 nil 的 *bytes.BytesReader 就 `invalid memory address or nil pointer dereference`
出错的代码如下:
func getEab(ctx context.Context, credentialsJSON string, old *externalAccountKeyResp) (*externalAccountKeyResp, error) {
// init http client
//
var postData *bytes.Reader = nil
if old != nil {
buf, _ := json.Marshal(old)
postData = bytes.NewReader(buf)
}
var api = fmt.Sprintf("https://publicca.googleapis.com/v1beta1/projects/%s/locations/global/externalAccountKeys", "xxxx")
resp, err := conf.Client(context.Background()).Post(api, "application/json", postData)
最后一行代码出现:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1024b56d0]
goroutine 36 [running]:
bytes.(*Reader).Len(...)
/opt/homebrew/Cellar/go/1.20.4/libexec/src/bytes/reader.go:27
net/http.NewRequestWithContext({0x102f2d2c8?, 0x140000340b8}, {0x102a565e4?, 0x1035bef20?}, {0x140005b8120?, 0x5e?}, {0x102f24be0, 0x0?})
/opt/homebrew/Cellar/go/1.20.4/libexec/src/net/http/request.go:909 +0x3e0
net/http.NewRequest(...)
/opt/homebrew/Cellar/go/1.20.4/libexec/src/net/http/request.go:840
net/http.(*Client).Post(0x102a8fcf2?, {0x140005b8120?, 0x140000340b8?}, {0x102a5fc1e, 0x10}, {0x102f24be0?, 0x0?})
/opt/homebrew/Cellar/go/1.20.4/libexec/src/net/http/client.go:844 +0x6c
github.com/myklst/terraform-provider-st-gcp/gcp.gcpGetEab({0x102f2d338?, 0x140005a2cf0?}, {0x140005ef500, 0x920}, 0x0)
/Users/fuchunzhang/code/github.com/ahfuzhang/terraform-provider-st-gcp/gcp/resource_eab.go:223 +0x348
github.com/myklst/terraform-provider-st-gcp/gcp.(*gcpAcmeEabResource).Create(0x0?, {0x102f2d338, 0x140005a2cf0}, {{{{0x102f31510, 0x140005a3c50}, {0x102d37d40, 0x140005a37d0}}, {0x102f32a00, 0x14000622410}}, {{{0x102f31510, ...}, ...}, ...}, ...}, ...)
/Users/fuchunzhang/code/github.com/ahfuzhang/terraform-provider-st-gcp/gcp/resource_eab.go:83 +0x15c
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0x14000349b80, {0x102f2d338, 0x140005a2cf0}, 0x14000545380, 0x14000545320)
/Users/fuchunzhang/go/pkg/mod/github.com/hashicorp/terraform-plugin-framework@v1.1.1/internal/fwserver/server_createresource.go:97 +0x428
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0x140005454e0?, {0x102f2d338, 0x140005a2cf0}, 0x140005aa410, 0x140005454e0)
/Users/fuchunzhang/go/pkg/mod/github.com/hashicorp/terraform-plugin-framework@v1.1.1/internal/fwserver/server_applyresourcechange.go:54 +0x370
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ApplyResourceChange(0x14000349b80, {0x102f2d338?, 0x140005a2ba0?}, 0x140005aa370)
/Users/fuchunzhang/go/pkg/mod/github.com/hashicorp/terraform-plugin-framework@v1.1.1/internal/proto6server/server_applyresourcechange.go:52 +0x314
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0x140001b4280, {0x102f2d338?, 0x140005a21b0?}, 0x14000264070)
/Users/fuchunzhang/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov6/tf6server/server.go:816 +0x3bc
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x102edc4c0?, 0x140001b4280}, {0x102f2d338, 0x140005a21b0}, 0x14000264000, 0x0)
/Users/fuchunzhang/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400014e000, {0x102f317f8, 0x14000582b60}, 0x140005b4000, 0x1400010f080, 0x1035b16c0, 0x0)
/Users/fuchunzhang/go/pkg/mod/google.golang.org/grpc@v1.55.0/server.go:1337 +0xc90
google.golang.org/grpc.(*Server).handleStream(0x1400014e000, {0x102f317f8, 0x14000582b60}, 0x140005b4000, 0x0)
/Users/fuchunzhang/go/pkg/mod/google.golang.org/grpc@v1.55.0/server.go:1714 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
/Users/fuchunzhang/go/pkg/mod/google.golang.org/grpc@v1.55.0/server.go:959 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
/Users/fuchunzhang/go/pkg/mod/google.golang.org/grpc@v1.55.0/server.go:957 +0x16c
换成如下的写法后,问题解决:
if old != nil {
buf, _ := json.Marshal(old)
resp, err = conf.Client(context.Background()).Post(api, "application/json", bytes.NewReader(buf))
} else {
resp, err = conf.Client(context.Background()).Post(api, "application/json", nil)
}
暂未想到原因。
【遇到一个神奇的问题】暂未想到原因,http.Post 传入 nil参数正确,但是传输值为 nil 的 *bytes.BytesReader 就 `invalid memory address or nil pointer dereference`的更多相关文章
- 记一个神奇的WAS问题:sibuswsgw-sibuswsgw_console.jar invalid LOC header (bad signature) 分类: WebSphere 2015-08-06 23:21 9人阅读 评论(0) 收藏
今天晚上,出现了一个神奇的WAS问题,详细问题异常信息如下: [15-8-6 22:13:29:146 CST] 00000013 ApplicationMg A WSVR0203I: 应用程序:is ...
- 视觉暂留-Info:这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝!
ylbtech-视觉暂留-Info:这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝! 1.返回顶部 1. 这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝! 原创|发布:2018-05-28 19: ...
- WWW 2015:一个神奇的会议
2015:一个神奇的会议" title="WWW 2015:一个神奇的会议"> 作者:微软亚洲研究院研究员 袁进辉 WWW 2015(24th Internatio ...
- openerp学习笔记 计算字段、关联字段(7.0中非计算字段、关联字段只读时无法修改保存的问题暂未解决)
计算字段.关联字段,对象修改时自动变更保存(当 store=True 时),当 store=False 时,默认不支持过滤和分组7.0中非计算字段.关联字段只读时无法修改保存的问题暂未解决 示例代码: ...
- modifytime是一个神奇的column name----这边文章是错的totally,因为我的实验不彻底。timestamp属性很神奇,头一个timestamp,会自动的成DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
在mysql里边modifytime是一个神奇的column name,试一下. 请执行sql语句 CREATE TABLE `test_time` ( `modifytime` timestamp ...
- 一个神奇的???whatever~~
一个神奇的类,用来封装消息数据,统一数据传递接口,从unity引擎源码拷贝而来. #include <iostream> #include <assert.h> #includ ...
- Jfrog Artifactory jenkins 流水线使用docker的方式培训[暂未成功]
1. 创建jenkins的流水线 2. 创建artifactory的镜像仓库 3. 创建generic的仓库上传需要的 war包还有tar包. 4. 修改pipeline的 脚本 主要修改的地方. 修 ...
- js 编写一个神奇的四则运算
写一个算法,有时候可以用简单的方法就可以写出来,但是只能针对特定的环境,如果要能够适应不同的环境,就需要对算法进行优化,在优化的过程中,你会觉得非常神奇,下面来看一个简单的四则运算的算法编写方式: 1 ...
- 微信图片上传,遇到一个神奇的jgp
微信图片上传,获取图片base64遇到一个神奇的 jgp var imgFn = function (event) { event.preventDefault(); var id = '#'+$ ...
- JS高级---一个神奇的原型链
一个神奇的原型链 <script> var divObj=document.getElementById("dv"); console.dir(divObj); //d ...
随机推荐
- centos8 nginx server root指向自定义目录如(/data/www),访问报403 404,所有文件用户组为root 权限为755
centos8 yum 自定义安装的nginx,修改nginx默认默认目录,指向自定义的目录 /data/www,访问报404,所有文件用户组为root 权限为755 nginx 以user 为ngi ...
- 非root安装Anaconda
1.下载对应版本的Anaconda (wget+路径) 下载地址:https://repo.anaconda.com/archive/ 或者清华镜像:https://mirrors.tuna.tsin ...
- 使用appuploader工具发布证书和描述性文件教程
使用APPuploader工具发布证书和描述性文件教程 之前用AppCan平台开发了一个应用,平台可以同时生成安卓版和苹果版,想着也把这应用上架到App Store试试,于是找同学借了个苹果开发者账号 ...
- 如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
在字节跳动各产品线飞速成长的过程中,对数据分析能力也提出了更高的要求,现有的主流数据分析产品都没办法完全满足业务要求.因此,字节跳动在ClickHouse引擎基础上重构了技术架构,实现了云原生环境的部 ...
- ZK--简介,部署
官网:https://zookeeper.apache.org/ 本文zk版本:3.7.0 一.简介 ZooKeeper 是一个高可用的分布式数据管理与系统协调软件,它可以为分布式应用提供状态同步.配 ...
- 【库函数】QT 中QString字符串的操作
QString是QT提供的字符串类,相应的也就提供了很多很方便对字符串的处理方法.这里把这些对字符串的操作做一个整理和总结. 1. 将一个字符串追加到另一个字符串的末尾 QString str1 = ...
- 【RK3399】2.制作ubuntu20.04 roomfs
firefly自带的文件系统,由于缺少一些基本功能模块,因此,我们可以自己手动制作一个ubuntu20.04的文件系统. 下载Ubuntu根文件系统 http://cdimage.ubuntu.com ...
- node-sass安装失败,安装后无法使用 gyp verb check python checking for Python executable "python2" in the PATH
这个问题搞了一会想起开始安装node-sass时的一句被我忽略的提示:执行 npm rebuild node-sass 这行后就可以了. 再说说 node-sass 的安装问题,现在使用 yarn i ...
- sipp3.6 on centos7安装部署
概述 在VOIP软交换的开发过程中,必然需要对软交换进行批量压测. SIP压测工具一般都是sipp,免费,开源,功能足够强大,配置灵活,优点多. 环境 centos7.9 cmake3.6 sipp ...
- C#树的实现
ddd /// <summary> /// 遍历,线索化等操作的接口 /// </summary> interface ITravelBinTree { void PreOrd ...