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

add retries for postgres auto user proc creation #47305

Merged
merged 2 commits into from
Oct 8, 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
2 changes: 1 addition & 1 deletion e2e/aws/databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func awsDBDiscoveryUnmatched(t *testing.T) {
}

const (
waitForConnTimeout = 60 * time.Second
waitForConnTimeout = 90 * time.Second
connRetryTick = 10 * time.Second
)

Expand Down
16 changes: 12 additions & 4 deletions lib/srv/db/postgres/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func (e *Engine) ActivateUser(ctx context.Context, sessionCtx *common.Session) e
return trace.Wrap(err)
}

if err := e.createProcedures(ctx, sessionCtx, conn, []string{activateProcName, deactivateProcName}); err != nil {
err = withRetry(ctx, logger, func() error {
err := e.createProcedures(ctx, sessionCtx, conn, []string{activateProcName, deactivateProcName})
return trace.Wrap(err)
})
if err != nil {
return trace.Wrap(err)
}

Expand Down Expand Up @@ -295,12 +299,16 @@ func (e *Engine) DeactivateUser(ctx context.Context, sessionCtx *common.Session)
}
defer conn.Close(ctx)

if err := e.createProcedures(ctx, sessionCtx, conn, []string{deactivateProcName}); err != nil {
logger := e.Log.With("user", sessionCtx.DatabaseUser)
logger.InfoContext(ctx, "Deactivating PostgreSQL user.")
err = withRetry(ctx, logger, func() error {
err := e.createProcedures(ctx, sessionCtx, conn, []string{deactivateProcName})
return trace.Wrap(err)
})
if err != nil {
return trace.NewAggregate(errRemove, trace.Wrap(err))
}

logger := e.Log.With("user", sessionCtx.DatabaseUser)
logger.InfoContext(ctx, "Deactivating PostgreSQL user.")
err = withRetry(ctx, logger, func() error {
return trace.Wrap(e.callProcedure(ctx, sessionCtx, conn, deactivateProcName, sessionCtx.DatabaseUser))
})
Expand Down
Loading