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

Set max number of connections to 1 #145

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions mysql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
)

const (
cleartextPasswords = "cleartext"
nativePasswords = "native"
unknownUserErrCode = 1396
cleartextPasswords = "cleartext"
nativePasswords = "native"
userNotFoundErrCode = 1133
unknownUserErrCode = 1396
)

type OneConnection struct {
Expand Down Expand Up @@ -532,7 +533,11 @@
return nil, fmt.Errorf("could not connect to server: %s", retryError)
}
db.SetConnMaxLifetime(conf.MaxConnLifetime)
db.SetMaxOpenConns(conf.MaxOpenConns)

// We used to set conf.MaxOpenConns, but then some connections are open outside our control
// and without our settings like no ANSI_QUOTES.
// TODO: find a way to support more open connections while able to set custom settings for each of them.
db.SetMaxOpenConns(1)

currentVersion, err := afterConnectVersion(ctx, conf, db)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions mysql/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ func ReadUser(ctx context.Context, d *schema.ResourceData, meta interface{}) dia
var createUserStmt string
err := db.QueryRowContext(ctx, stmt, d.Get("user").(string), d.Get("host").(string)).Scan(&createUserStmt)
if err != nil {
if mysqlErrorNumber(err) == unknownUserErrCode {
if mysqlErrorNumber(err) == unknownUserErrCode || mysqlErrorNumber(err) == userNotFoundErrCode {
d.SetId("")
return nil
}
return diag.Errorf("failed getting version: %v", err)
return diag.Errorf("failed getting user: %v", err)
}

// Examples of create user:
Expand Down
Loading