Skip to content

Conversation

lunny
Copy link
Member

@lunny lunny commented Mar 3, 2021

Fix #14821

@lunny lunny added the type/bug label Mar 3, 2021
@lunny lunny force-pushed the lunny/repo_transfer_rollback branch from 4f5be46 to 31094d6 Compare March 4, 2021 03:11
@lunny lunny added this to the 1.14.0 milestone Mar 4, 2021
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 4, 2021
@zeripath
Copy link
Contributor

zeripath commented Mar 4, 2021

This probably also needs a panic handler too.

My suspicion is that putting the return in a defer would be better:

e.g.

func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err error) {
   repoRenamed := false
   wikiRenamed := false
  
   defer func() {
       recErr := recover()

       if recErr != nil || err != nil {
          // handle moving stuff back
          // If there is an error moving stuff back this needs a clear log.Critical(...) so administrators know that they need to do something
      } ()
      ...
   }

Then you can just err = sess.Commit() and return err

Something like that.

@lunny
Copy link
Member Author

lunny commented Mar 4, 2021

This probably also needs a panic handler too.

My suspicion is that putting the return in a defer would be better:

e.g.

func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err error) {
   repoRenamed := false
   wikiRenamed := false
  
   defer func() {
       recErr := recover()

       if recErr != nil || err != nil {
          // handle moving stuff back
          // If there is an error moving stuff back this needs a clear log.Critical(...) so administrators know that they need to do something
      } ()
      ...
   }

Then you can just err = sess.Commit() and return err

Something like that.

It's running beyond on http router, and I think we have already recovery middleware there.

@zeripath
Copy link
Contributor

zeripath commented Mar 4, 2021

yes but if there is a panic after the initial rename has occurred but then you're not going to rename back unless you use a recover deferral scheme as I suggest above.

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor

zeripath commented Mar 4, 2021

See lunny#14

zeripath and others added 2 commits March 4, 2021 17:41
Signed-off-by: Andrew Thornton <art27@cantab.net>
Use defer to ensure that reporollback occurs
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 5, 2021
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 5, 2021
@6543 6543 merged commit 7525450 into go-gitea:master Mar 5, 2021
@lunny lunny deleted the lunny/repo_transfer_rollback branch March 5, 2021 06:21
6543 added a commit to 6543-forks/gitea that referenced this pull request Mar 6, 2021
… the renames (go-gitea#14864)

Fix go-gitea#14821

Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
@6543 6543 added the backport/done All backports for this PR have been created label Mar 6, 2021
lunny added a commit that referenced this pull request Mar 6, 2021
… the renames (#14864) (#14902)

Fix #14821

Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repo Transfer: If the sql transaction fails we will be left repository in the wrong place
4 participants