Skip to content

Commit

Permalink
add retries for postgres auto user proc creation (#47305)
Browse files Browse the repository at this point in the history
* add retries for postgres auto user proc creation

* bump the conn timeout up
  • Loading branch information
GavinFrazar authored Oct 8, 2024
1 parent 4c0c41e commit 579db5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit 579db5e

Please sign in to comment.