Skip to content

Commit

Permalink
secret/database: ensure plugins are closed if they cannot be initiali…
Browse files Browse the repository at this point in the history
…zed (#3768)
  • Loading branch information
briankassouf authored Jan 9, 2018
1 parent c9e5cd5 commit 05f2030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 13 additions & 0 deletions builtin/logical/database/dbplugin/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dbplugin

import (
"context"
"errors"
"sync"

Expand All @@ -18,13 +19,25 @@ type DatabasePluginClient struct {
Database
}

// This wraps the Close call and ensures we both close the database connection
// and kill the plugin.
func (dc *DatabasePluginClient) Close() error {
err := dc.Database.Close()
dc.client.Kill()

return err
}

// This wraps the Initialize call and ensures we close the plugin on error.
func (dc *DatabasePluginClient) Initialize(ctx context.Context, config map[string]interface{}, verifyConnection bool) error {
err := dc.Database.Initialize(ctx, config, verifyConnection)
if err != nil {
dc.Close()
}

return err
}

// newPluginClient returns a databaseRPCClient with a connection to a running
// plugin. The client is wrapped in a DatabasePluginClient object to ensure the
// plugin is killed on call of Close().
Expand Down
1 change: 0 additions & 1 deletion builtin/logical/database/path_config_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ func (b *databaseBackend) connectionWriteHandler() framework.OperationFunc {

err = db.Initialize(ctx, config.ConnectionDetails, verifyConnection)
if err != nil {
db.Close()
return logical.ErrorResponse(fmt.Sprintf("error creating database object: %s", err)), nil
}

Expand Down

0 comments on commit 05f2030

Please sign in to comment.