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

Savepoint names can be duplicated #4492

Closed
wizzard0 opened this issue Jul 1, 2021 · 3 comments
Closed

Savepoint names can be duplicated #4492

wizzard0 opened this issue Jul 1, 2021 · 3 comments
Assignees
Labels

Comments

@wizzard0
Copy link

wizzard0 commented Jul 1, 2021

Description

err = db.SavePoint(fmt.Sprintf("sp%p", fc)).Error

In this line, savepoint name is generated from the pointer to the callback passed to the gorm.Transaction function.

If you ever reuse the callback, or the closure happens to be allocated at the same address, the transaction will silently fail.

Please allow to pass the savepoint name, or at least add some randomness there.

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Jul 1, 2021
@github-actions
Copy link

github-actions bot commented Jul 1, 2021

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@pitluga
Copy link

pitluga commented Apr 23, 2024

This bit me as well. In order to work around it, I kept track of the nested depth of my transactions and uses a different copy of the function. If you do a switch statement, you can get different pointers for different nested depths. Something like:

var txfn func(tx *gorm.DB) error

switch depth {
case 0: 
  txfn = func(tx *gorm.DB) error { ... }
case 1: 
  txfn = func(tx *gorm.DB) error { ... }
case n: 
  txfn = func(tx *gorm.DB) error { ... }
default:
  return errors.New("too deep")
}

@phroggyy
Copy link
Contributor

Re-reported and reproduced in #7173, fix in #7174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants