Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
115735: workload/schemachange: `Release` connection only when acquired r=rafiss a=renatolabs

Previously, we would call `defer conn.Release` before the we were sure if we actually acquired a connection, which could lead to nil pointer dereference panics in case of error.

Epic: none

Release note: None

Co-authored-by: Renato Costa <[email protected]>
  • Loading branch information
craig[bot] and renatolabs committed Dec 7, 2023
2 parents dd062fd + ba017c3 commit 161d4f5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/workload/schemachange/schemachange.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ func (w *schemaChangeWorker) runInTxn(

func (w *schemaChangeWorker) run(ctx context.Context) error {
conn, err := w.pool.Get().Acquire(ctx)
defer conn.Release()
if err != nil {
return errors.Wrap(err, "cannot get a connection")
}
defer conn.Release()
useDeclarativeSchemaChanger := w.opGen.randIntn(100) < w.workload.declarativeSchemaChangerPct
if useDeclarativeSchemaChanger {
if _, err := conn.Exec(ctx, "SET use_declarative_schema_changer='unsafe_always';"); err != nil {
Expand Down

0 comments on commit 161d4f5

Please sign in to comment.