Skip to content

pgx transaction example improvements #3808

Closed

Description

@abh

Version

1.28.0

What happened?

The example for how to do transactions with pgx added in #3557 will always run Rollback. The rollback will return an error which appears silent, but isn't if pgx is wrapped in opentelemetry tracing.

Instead of always doing a Rollback I believe you can make a context.WithCancel context and then defer cancel() will rollback the transaction if it's not already committed.

Relevant log output

Database schema

SQL queries

Configuration

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

Activity

  1. added
    bugSomething isn't working
    on Jan 25, 2025
  2. crhntr commented on Feb 4, 2025

    @crhntr

    This documentation seems relevant: https://pkg.go.dev/github.com/jackc/pgx/v5#Conn.BeginTx

    ...there is no auto-rollback on context cancellation.

  3. abh commented on Feb 5, 2025

    @abh
    Author

    doh, thanks @crhntr!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions