Skip to content

Commit build status not updating (intermittent) #14059

Closed
@bobemoe

Description

@bobemoe
  • Gitea version (or commit ref): 1.14.0+dev-414-g4ef751215
  • Git version: 2.20.1
  • Operating system: Debian based
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite

Description

Occasionally one of my Drone builds will not update it's status properly, leaving the commit as "Build in progress" with the yellow circle, when actually checking Drone it shows "Successful", or "Failed".

This only happens occasionally, the only pattern I can see is its only been for PR's so far, and also when the server is under heavy load. I first noticed when I ran "update branch" on 4 PR's at the same time, each calls 2 builds, so I have many builds queued.

From the logs, the error seems to be a SQL duplicate value in the unique index.

[17/Dec/2020:09:27:30 +0000] "GET /api/v1/repos/xxxx/xxxx/raw/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8/.drone.yml HTTP/1.1" 200 2553 "-" "Go-http-client/1.1"
[17/Dec/2020:09:27:30 +0000] "POST /api/v1/repos/xxxx/xxxx/statuses/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8 HTTP/1.1" 201 638 "-" "Go-http-client/1.1"
[17/Dec/2020:09:27:31 +0000] "POST /api/v1/repos/xxxx/xxxx/statuses/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8 HTTP/1.1" 201 636 "-" "Go-http-client/1.1"
[17/Dec/2020:09:45:09 +0000] "POST /api/v1/repos/xxxx/xxxx/statuses/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8 HTTP/1.1" 201 638 "-" "Go-http-client/1.1"
[17/Dec/2020:09:45:22 +0000] "POST /api/v1/repos/xxxx/xxxx/statuses/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8 HTTP/1.1" 201 636 "-" "Go-http-client/1.1"
[17/Dec/2020:09:50:59 +0000] "POST /api/v1/repos/xxxx/xxxx/statuses/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8 HTTP/1.1" 201 636 "-" "Go-http-client/1.1"
[17/Dec/2020:09:50:59 +0000] "POST /api/v1/repos/xxxx/xxxx/statuses/a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8 HTTP/1.1" 500 375 "-" "Go-http-client/1.1"
2020/12/17 09:50:59 ...pi/v1/repo/status.go:64:NewCommitStatus() [E] CreateCommitStatus: NewCommitStatus[repo_id: 1, user_id: 1, sha: a12437fc1f5b4153a3e25f9b8d82a39d
20b7e7e8]: Insert CommitStatus[/home/git/gitea-repositories/xxxx/xxxx.git, a12437fc1f5b4153a3e25f9b8d82a39d20b7e7e8]: Error 1062: Duplicate entry '5-1-a12437fc1f5b
4153a3e25f9b8d82a39d20b7e7e8' for key 'UQE_commit_status_repo_sha_index'

Looking at how the index is generated, I'm guessing two status updates came in simultaneously and both generated the same value? Maybe a lock on the db table is needed during index increment?

// Get the next Status Index
var nextIndex int64
lastCommitStatus := &CommitStatus{
SHA: opts.SHA,
RepoID: opts.Repo.ID,
}
has, err := sess.Desc("index").Limit(1).Get(lastCommitStatus)
if err != nil {
if err := sess.Rollback(); err != nil {
log.Error("NewCommitStatus: sess.Rollback: %v", err)
}
return fmt.Errorf("NewCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err)
}
if has {
log.Debug("NewCommitStatus[%s, %s]: found", repoPath, opts.SHA)
nextIndex = lastCommitStatus.Index
}
opts.CommitStatus.Index = nextIndex + 1
log.Debug("NewCommitStatus[%s, %s]: %d", repoPath, opts.SHA, opts.CommitStatus.Index)
opts.CommitStatus.ContextHash = hashCommitStatusContext(opts.CommitStatus.Context)

I notice that file has been updated yesterday, but looking at the code it looks like the index is still generated the same way. I will update my gitea anyway and keep an eye on things. Just happened again on latest master. I've updated Gitea version above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions