Multiple concurrent API requests against repository.

Summary

When using multiple concurrent accesses to the files repository through the API, the "first" request goes ahead, while the followings get a 400 BadRequest response.

Steps to reproduce

Just run 2 concurrent curl in parallel

curl -v https://HOST/api/v4/projects/:id/repository/files/filename -H "Private-token: XXXXXXXXXXXXXXXXXXXX" --data "branch=master&content=thecontent1&commit_message=msg1" -X PUT & \
curl -v https://HOST/api/v4/projects/:id/repository/files/filename -H "Private-token: XXXXXXXXXXXXXXXXXXXX" --data "branch=master&content=thecontent2&commit_message=msg2" -X PUT

What is the current bug behavior?

There is a race condition between the two of them: one gets 200 OK, the other gets 400 BadRequest. Note that they are formally the very same request.

What is the expected correct behavior?

Both of them should get 200 OK. No matter of the content pushed. It is expected a race condition over the content (the last scheduled overwrites the previous, but both of them should pass and appear in the commit log).

Relevant logs and/or screenshots

The curl outputs are

{"file_path":"filename","branch":"master"}
{"message":"Could not update branch master. Please refresh and try again."}

Output of checks

Happens on gitlab-ce.

Results of GitLab environment info

System information
System:		Ubuntu 16.04
Current User:	git
Using RVM:	no
Ruby Version:	2.3.3p222
Gem Version:	2.6.6
Bundler Version:1.13.7
Rake Version:	10.5.0
Redis Version:	3.2.5
Git Version:	2.11.1
Sidekiq Version:4.2.7

GitLab information Version: 9.1.2 Revision: df1403f Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: https://tip.telecomitalia.local HTTP Clone URL: https://tip.telecomitalia.local/some-group/some-project.git SSH Clone URL: git@tip.telecomitalia.local:some-group/some-project.git Using LDAP: yes Using Omniauth: no

GitLab Shell Version: 5.0.2 Repository storage paths:

  • default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git

Results of GitLab application Check

Checking GitLab Shell ...

GitLab Shell version >= 5.0.2 ? ... OK (5.0.2) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by git:git? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 3/1 ... ok 3/2 ... repository is empty 3/3 ... ok 3/5 ... repository is empty 3/8 ... ok 3/9 ... ok 25/10 ... ok 3/11 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Access to /var/opt/gitlab/.ssh/authorized_keys: OK Send ping to redis server: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

Server: ldapmain LDAP authentication... Anonymous. No bind_dn or password configured LDAP users with access to your GitLab server (only showing the first 100 results) [CUT]

Checking LDAP ... Finished

Checking GitLab ...

Git configured with autocrlf=input? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config outdated? ... no Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory setup correctly? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) projects have namespace: ... 3/1 ... yes 3/2 ... yes 3/3 ... yes 3/5 ... yes 3/8 ... yes 3/9 ... yes 25/10 ... yes 3/11 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.1.0 ? ... yes (2.3.3) Your git bin path is "/opt/gitlab/embedded/bin/git" Git version >= 2.7.3 ? ... yes (2.11.1) Active users: 21

Checking GitLab ... Finished

Possible fixes

Not yet.

Edited by 🤖 GitLab Bot 🤖