From a2b9ce7de8edc941406bb516e23858ea96790a55 Mon Sep 17 00:00:00 2001 From: Brian Kassouf Date: Wed, 10 Jan 2018 13:07:55 -0800 Subject: [PATCH] remove the Initialize wrap and call close explicitly (#3769) --- builtin/logical/database/backend.go | 1 + builtin/logical/database/dbplugin/client.go | 11 ----------- builtin/logical/database/path_config_connection.go | 1 + 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/builtin/logical/database/backend.go b/builtin/logical/database/backend.go index a72cdefd6d5f..fdf4ec25b1a0 100644 --- a/builtin/logical/database/backend.go +++ b/builtin/logical/database/backend.go @@ -106,6 +106,7 @@ func (b *databaseBackend) createDBObj(ctx context.Context, s logical.Storage, na err = db.Initialize(ctx, config.ConnectionDetails, true) if err != nil { + db.Close() return nil, err } diff --git a/builtin/logical/database/dbplugin/client.go b/builtin/logical/database/dbplugin/client.go index 42c150e955c5..a71024f53413 100644 --- a/builtin/logical/database/dbplugin/client.go +++ b/builtin/logical/database/dbplugin/client.go @@ -1,7 +1,6 @@ package dbplugin import ( - "context" "errors" "sync" @@ -28,16 +27,6 @@ func (dc *DatabasePluginClient) Close() error { 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(). diff --git a/builtin/logical/database/path_config_connection.go b/builtin/logical/database/path_config_connection.go index 6ceb5facd7ac..852642791686 100644 --- a/builtin/logical/database/path_config_connection.go +++ b/builtin/logical/database/path_config_connection.go @@ -233,6 +233,7 @@ 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 }