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

Rework create/fork/adopt/generate repository to make sure resources will be cleanup once failed #31035

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

lunny
Copy link
Member

@lunny lunny commented May 21, 2024

Fix #28144

To make the resources will be cleanup once failed. All repository operations now follow a consistent pattern:

    1. Create a database record for the repository with the status being_migrated.
    1. Register a deferred cleanup function to delete the repository and its related data if the operation fails.
    1. Perform the actual Git and database operations step by step.
    1. Upon successful completion, update the repository’s status to ready.

The adopt operation is a special case — if it fails, the repository on disk should not be deleted.

@lunny lunny added type/bug backport/v1.22 This PR should be backported to Gitea 1.22 labels May 21, 2024
@lunny lunny added this to the 1.23.0 milestone May 21, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 21, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 21, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label May 21, 2024
@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 May 27, 2024
Copy link
Contributor

@yp05327 yp05327 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateRepositoryNotice has two same messages, maybe it is better to adjust them

@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 May 27, 2024
@lunny
Copy link
Member Author

lunny commented May 27, 2024

I will try to have some tests.

@yp05327 yp05327 self-requested a review May 27, 2024 23:32
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels May 27, 2024
@lunny lunny marked this pull request as draft August 22, 2024 04:46
@lunny lunny modified the milestones: 1.23.0, 1.24.0 Sep 7, 2024
@lunny lunny modified the milestones: 1.24.0, 1.23.0 Sep 23, 2024
@lunny lunny marked this pull request as ready for review September 23, 2024 17:23
@lunny lunny marked this pull request as draft September 23, 2024 18:14
@lunny lunny modified the milestones: 1.23.0, 1.24.0 Sep 24, 2024
@lunny lunny removed the backport/v1.22 This PR should be backported to Gitea 1.22 label Dec 25, 2024
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 26, 2025
@lunny lunny marked this pull request as ready for review March 27, 2025 04:32
@lunny lunny changed the title Cleanup resources when create/adopt/generate repository failed Rework create/fork/adopt/generate repository to make sure resources will be cleanup once failed Mar 27, 2025
@lunny lunny added the backport/v1.23 This PR should be backported to Gitea 1.23 label Mar 27, 2025
Copy link
Contributor

@jtran jtran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read through it, and the overall logic looks good to me. But sorry, I've been away from Gitea development for too long to comment on the details. I think I wrote down everything I knew about the problem in the linked issue when I created it.

@yp05327
Copy link
Contributor

yp05327 commented Mar 29, 2025

In the tests, timeout is set to 1ms.
I'm afraid this can not test well as db record and git files may not even created, then the timeout happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v1.23 This PR should be backported to Gitea 1.23 lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template repo files should be cleaned up after an error
5 participants