Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Connect errors are hard to debug in autosetup with Postgres #1577

Closed
pquerna opened this issue May 27, 2021 · 1 comment · Fixed by #1581
Closed

SQL Connect errors are hard to debug in autosetup with Postgres #1577

pquerna opened this issue May 27, 2021 · 1 comment · Fixed by #1581

Comments

@pquerna
Copy link
Contributor

pquerna commented May 27, 2021

Expected Behavior

When SQL connection is misconfigured, show a more accurate error message.

Actual Behavior

I had misconfigured TLS client certificates when using the autosetup container, using Postgres

This was difficult to debug, because the container would log like this:

+ SCHEMA_DIR=/etc/temporal/schema/postgresql/v96/temporal/versioned
+ temporal-sql-tool --plugin postgres --ep 127.0.0.1 -u postgres -p 5432 create --db temporal
2021/05/27 21:22:03 error creating database:unable to connect to DB, tried default DB names: postgres,defaultdb

Steps to Reproduce the Problem

When temporal-sql-tool is invoked with create, it sets the DatabaseName to "", and then invokes tryConnect/sqlx.Connect:

func (d *plugin) tryConnect(
cfg *config.SQL,
r resolver.ServiceResolver,
) (*sqlx.DB, error) {
if cfg.DatabaseName != "" {
return sqlx.Connect(PluginName, buildDSN(cfg, r))
}
// database name not provided
// try defaults
defer func() { cfg.DatabaseName = "" }()
for _, databaseName := range defaultDatabaseNames {
cfg.DatabaseName = databaseName
if sqlxDB, err := sqlx.Connect(PluginName, buildDSN(cfg, r)); err == nil {
return sqlxDB, nil
}
}
return nil, serviceerror.NewInternal(
fmt.Sprintf("unable to connect to DB, tried default DB names: %v", strings.Join(defaultDatabaseNames, ",")),
)
}

Errors from the loop of trying different default DB names are ignored - instead a static string error is returned. Ideally this message would also include the Last error (or all of the errors) -- this would of made it more obvious I had misconfigured TLS.

@pquerna
Copy link
Contributor Author

pquerna commented May 27, 2021

Looks like change was recently changed via #1413

@pquerna pquerna changed the title SQL Connect errors are hard to debug in autosetup SQL Connect errors are hard to debug in autosetup with Postgres May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant