Re-initialize v5 backend after a plugin crash (#17140)
This commit is contained in:
parent
5a8a896b5a
commit
c548ea39be
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"os"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/vault/api"
|
||||
"github.com/hashicorp/vault/builtin/logical/aws"
|
||||
"github.com/hashicorp/vault/sdk/plugin"
|
||||
|
|
|
@ -46,7 +46,7 @@ type backend struct {
|
|||
canary string
|
||||
}
|
||||
|
||||
func (b *backend) reloadBackend(ctx context.Context) error {
|
||||
func (b *backend) reloadBackend(ctx context.Context, storage logical.Storage) error {
|
||||
pluginName := b.config.Config["plugin_name"]
|
||||
pluginType, err := consts.ParsePluginType(b.config.Config["plugin_type"])
|
||||
if err != nil {
|
||||
|
@ -72,6 +72,16 @@ func (b *backend) reloadBackend(ctx context.Context) error {
|
|||
}
|
||||
b.Backend = nb
|
||||
|
||||
// Re-initialize the backend in case plugin was reloaded
|
||||
// after it crashed
|
||||
err = b.Backend.Initialize(ctx, &logical.InitializationRequest{
|
||||
Storage: storage,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -88,7 +98,7 @@ func (b *backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
|
|||
// Reload plugin if it's an rpc.ErrShutdown
|
||||
b.mu.Lock()
|
||||
if b.canary == canary {
|
||||
err := b.reloadBackend(ctx)
|
||||
err := b.reloadBackend(ctx, req.Storage)
|
||||
if err != nil {
|
||||
b.mu.Unlock()
|
||||
return nil, err
|
||||
|
@ -120,7 +130,7 @@ func (b *backend) HandleExistenceCheck(ctx context.Context, req *logical.Request
|
|||
// Reload plugin if it's an rpc.ErrShutdown
|
||||
b.mu.Lock()
|
||||
if b.canary == canary {
|
||||
err := b.reloadBackend(ctx)
|
||||
err := b.reloadBackend(ctx, req.Storage)
|
||||
if err != nil {
|
||||
b.mu.Unlock()
|
||||
return false, false, err
|
||||
|
|
Loading…
Reference in New Issue