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

Retrying the insert on issue fails, and masks the actual error #8302

Closed
guillep2k opened this issue Sep 27, 2019 · 6 comments
Closed

Retrying the insert on issue fails, and masks the actual error #8302

guillep2k opened this issue Sep 27, 2019 · 6 comments
Labels
Milestone

Comments

@guillep2k
Copy link
Member

  • Gitea version (or commit ref): c6fb7fe

Description

The changes introduced in #7898 simply don't work, because if xorm.Session.Insert() returns any errors, the session becomes invalidated, so subsequent attempts fail with:

newIssue: pq: current transaction is aborted, commands ignored until end of transaction block

gitea/models/issue.go

Lines 1108 to 1122 in c6fb7fe

// There's no good way to identify a duplicate key error in database/sql; brute force some retries
dupIndexAttempts := issueMaxDupIndexAttempts
for {
_, err := e.SetExpr("`index`", "coalesce(MAX(`index`),0)+1").
Where("repo_id=?", opts.Issue.RepoID).
Insert(opts.Issue)
if err == nil {
break
}
dupIndexAttempts--
if dupIndexAttempts <= 0 {
return err
}
}

I'm sorry, after so many attempts to solve the potential duplicate index, we're back to square zero.

@lunny how would you like to handle this?

@lunny
Copy link
Member

lunny commented Sep 28, 2019

The retry should be done after the transaction end. It should be out of newIssue but we should return the reason of failed. So that we could know if we need retry.

@lunny lunny added the type/bug label Sep 28, 2019
@guillep2k
Copy link
Member Author

The retry should be done after the transaction end. It should be out of newIssue but we should return the reason of failed. So that we could know if we need retry.

I agree, but as I've said here, detecting the correct error is very difficult.

@lunny
Copy link
Member

lunny commented Sep 28, 2019

If the error is insert error we could retry it, I think.

@guillep2k
Copy link
Member Author

If the error is insert error we could retry it, I think.

Oh, you mean any errors, as long as they come from the insert? That's much easier. I'll work on that. I'll asume that #8304 will be merged and I'll base on it.

@lunny
Copy link
Member

lunny commented Oct 3, 2019

Should be fixed by #8307

@guillep2k
Copy link
Member Author

Agree

@lunny lunny added this to the 1.10.0 milestone Oct 4, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants