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

Deadlock if BeginTx called with unexpected options #60

Closed
numberZero opened this issue Mar 5, 2022 · 1 comment
Closed

Deadlock if BeginTx called with unexpected options #60

numberZero opened this issue Mar 5, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@numberZero
Copy link

numberZero commented Mar 5, 2022

Describe the bug
If BeginTx (or BeginTxFunc) is called with unexpected options, ExpectationsWereMet deadlocks if called afterwards.

To Reproduce
In the example use db.BeginTx(context.Background(), pgx.TxOptions{IsoLevel: pgx.Serializable}) instead of db.Begin (requires adding BeginTx(context.Context, pgx.TxOptions) (pgx.Tx, error) to the PgxIface). Run tests.

Expected behavior
Error return from ExpectationsWereMet

Additional context
The problem seems to be here:

pgxmock/pgxmock.go

Lines 513 to 517 in ed5a923

if expected.opts != txOptions {
return nil, fmt.Errorf("Begin: call with transaction options '%v' was not expected, expected name is '%v'", txOptions, expected.opts)
}
expected.triggered = true
expected.Unlock()

Here expected.Unlock() is not called if expected.opts != txOptions.

@pashagolub pashagolub self-assigned this Mar 5, 2022
@pashagolub pashagolub added the bug Something isn't working label Mar 5, 2022
@pashagolub
Copy link
Owner

Thanks for your report. Would you please test #61

pashagolub added a commit that referenced this issue Mar 11, 2022
[-]  fix deadlock in `ExpectationsWereMet()` if `BeginTx()` called with unexpected options, fixes #60
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