From 16c9e9b5926694439342445ea030c50f48b51e8c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 7 Sep 2022 16:28:07 -0400 Subject: [PATCH] Add ability to skip shared lock acquisition --- internal/cmd/base/listener.go | 4 ++++ internal/cmd/commands/server/server.go | 32 ++++++++++++++------------ internal/cmd/config/config.go | 4 ++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/internal/cmd/base/listener.go b/internal/cmd/base/listener.go index df148b6f1..7ac47e00c 100644 --- a/internal/cmd/base/listener.go +++ b/internal/cmd/base/listener.go @@ -100,6 +100,10 @@ func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (net.Listener, map[s return ln, props, nil, nil } + if l.TLSCertFile == "" { + return nil, nil, nil, fmt.Errorf("tls not disabled for listener at address %q with purpose %q but no certificate file supplied", finalAddr, purpose) + } + // Don't request a client cert unless they've explicitly configured it to do // so if !l.TLSRequireAndVerifyClientCert { diff --git a/internal/cmd/commands/server/server.go b/internal/cmd/commands/server/server.go index af4e2958a..a8d88e097 100644 --- a/internal/cmd/commands/server/server.go +++ b/internal/cmd/commands/server/server.go @@ -438,22 +438,24 @@ func (c *Command) Run(args []string) int { c.UI.Error(fmt.Errorf("Can't get schema manager: %w.", err).Error()) return base.CommandCliError } - // This is an advisory locks on the DB which is released when the db session ends. - if err := sMan.SharedLock(c.Context); err != nil { - c.UI.Error(fmt.Errorf("Unable to gain shared access to the database: %w", err).Error()) - return base.CommandCliError - } - defer func() { - // The base context has already been canceled so we shouldn't use it here. - // 1 second is chosen so the shutdown is still responsive and this is a mostly - // non critical step since the lock should be released when the session with the - // database is closed. - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) - defer cancel() - if err := sMan.SharedUnlock(ctx); err != nil { - c.UI.Error(fmt.Errorf("Unable to release shared lock to the database: %w", err).Error()) + if !c.Config.Controller.Database.SkipSharedLockAcquisition { + // This is an advisory lock on the DB which is released when the db session ends. + if err := sMan.SharedLock(c.Context); err != nil { + c.UI.Error(fmt.Errorf("Unable to gain shared access to the database: %w", err).Error()) + return base.CommandCliError } - }() + defer func() { + // The base context has already been canceled so we shouldn't use it here. + // 1 second is chosen so the shutdown is still responsive and this is a mostly + // non critical step since the lock should be released when the session with the + // database is closed. + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + if err := sMan.SharedUnlock(ctx); err != nil { + c.UI.Error(fmt.Errorf("Unable to release shared lock to the database: %w", err).Error()) + } + }() + } ckState, err := sMan.CurrentState(c.Context) if err != nil { c.UI.Error(fmt.Errorf("Error checking schema state: %w", err).Error()) diff --git a/internal/cmd/config/config.go b/internal/cmd/config/config.go index 1c1de5600..046507f79 100644 --- a/internal/cmd/config/config.go +++ b/internal/cmd/config/config.go @@ -228,6 +228,10 @@ type Database struct { MaxIdleConnectionsRaw interface{} `hcl:"max_idle_connections"` ConnMaxIdleTime interface{} `hcl:"max_idle_time"` ConnMaxIdleTimeDuration *time.Duration `hcl:"-"` + + // SkipSharedLockAcquisition allows skipping grabbing the database shared + // lock. This is dangerous unless you know what you're doing. + SkipSharedLockAcquisition bool `hcl:"skip_shared_lock_acquisition"` } type Plugins struct {