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

pgx transaction example improvements #3808

Closed
abh opened this issue Jan 25, 2025 · 2 comments
Closed

pgx transaction example improvements #3808

abh opened this issue Jan 25, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@abh
Copy link

abh commented Jan 25, 2025

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

@abh abh added the bug Something isn't working label Jan 25, 2025
@crhntr
Copy link

crhntr commented Feb 4, 2025

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

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

@abh
Copy link
Author

abh commented Feb 5, 2025

doh, thanks @crhntr!

@abh abh closed this as completed Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants