我正在开发一个自定义插件,它是一个PKI后端,可以导入其他软件功能(https://github.com/Venafi/vault-pki-monitor-venafi)。
此插件具有在创建角色时在go例程中启动导入队列的逻辑,并监视角色中的新证书以将其导入到外部系统中:
-https://github.com/Venafi/vault-pki-monitor-venafi/blob/adding-tests-for-import/plugin/pki/path_import_queue.go#L83
-https://github.com/Venafi/vault-pki-monitor-venafi/blob/adding-tests-for-import/plugin/pki/path_roles.go#L606-L610
为确保每个角色只有一个import go例程,我正在创建一个锁定路径并将其设置为true:
https://github.com/Venafi/vault-pki-monitor-venafi/blob/adding-tests-for-import/plugin/pki/path_import_queue.go#L88-L153
如果不存在锁定路径,则假定它是错误的:
https://github.com/Venafi/vault-pki-monitor-venafi/blob/adding-tests-for-import/plugin/pki/path_import_queue.go#L112-L114
当我使用Vault二进制文件对其进行测试时,一切正常。但是,当我尝试使用vault.NewTestCluster-https://github.com/Venafi/vault-pki-monitor-venafi/blob/adding-tests-for-import/plugin/pki/path_import_queue_test.go#L16-L63实施测试时 我收到此错误:
2018-11-08T15:24:58.004+0300 [DEBUG] core: forwarding: error sending echo request to active node: error="rpc error: code = DeadlineExceeded desc = context deadline exceeded"
2018/11/08 15:25:23 Locking import mutex on backend to safely change data for import lock
2018/11/08 15:25:23 Getting import lock for path import-queue-lock/import
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x112863d]
goroutine 557 [running]:
github.com/Venafi/vault-pki-monitor-venafi/plugin/pki.(*backend).importToTPP(0xc4202d3360, 0xc4202ebece, 0x6, 0x14fa8e0, 0xc420040170, 0xc420295a40)
/home/user/src/go/src/github.com/Venafi/vault-pki-monitor-venafi/plugin/pki/path_import_queue.go:105 +0x2fd
created by github.com/Venafi/vault-pki-monitor-venafi/plugin/pki.(*backend).pathRoleCreate
/home/user/src/go/src/github.com/Venafi/vault-pki-monitor-venafi/plugin/pki/path_roles.go:609 +0x2a6b
这是我遇到错误的地方(与Vault二进制文件一起运行时效果很好,只有测试失败):
log.Printf("Getting import lock for path %s", lockPath)
var importLockEntry *logical.StorageEntry
importLockEntry, err = req.Storage.Get(ctx, lockPath)
if err != nil {
log.Printf("Unable to get lock import for role %s:\n %s\n", roleName, err)
unlock()
return
}
if importLockEntry == nil || importLockEntry.Value == nil || len(importLockEntry.Value) == 0 {
log.Println("Role lock is empty, assuming it is false")
importLocked = false
} else {
log.Printf("Got from storage %s", string(importLockEntry.Value))
il := string(importLockEntry.Value)
log.Printf("Parsing %s to bool", il)
importLocked, err = strconv.ParseBool(il)
if err != nil {
log.Printf("Unable to parse lock import %s to bool for role %s:\n %s\n", il, roleName, err)
unlock()
return
}
}
这是它在调试器中的外观: https://13027918075534280191.googlegroups.com/attach/5de3757908e52/Screenshot%20from%202018-11-09%2013-24-52.png
importLockEntry为nil,但我在使用前正在检查它,因此据我所知应该没问题。但是,我在https://github.com/Venafi/vault-pki-monitor-venafi/blob/adding-tests-for-import/plugin/pki/path_import_queue.go#L105(我要设置变量的行)上感到恐慌。
那么,我想念的是什么?为什么当我使用Vault二进制文件运行我的插件时,它运行良好,而当我尝试使用Vault.NewTestCluster运行它时,它会出现紧急情况?