Race creating projects via API gives 'null' return value
Summary
We noticed a weird output from gitlab when creating the same project twice simultaneously.
Why are we doing that? Because we have multiple workers which do a task involving ensuring that repositories exist, and sometimes two of them happen to notice one missing and try to create it at the same time.
FWIW, this has only happened once, but that 'once' required some debugging, which we would prefer to avoid.
Steps to reproduce
Start multiple requests to create the same project at the exact same time.
What is the current bug behavior?
We don't have an exact log of what was returned by gitlab, but our code exploration leads us to believe that, instead of an error or success, the json returned to one of the racers was 'null'.
What is the expected correct behavior?
Creating projects should probably be idempotent; a duplicate key should cause both requests to appear to succeed. But a normal failure would have been just fine too; then our code would have caught the exception, rather than seeing a null and wigging out.
Relevant logs and/or screenshots
Started POST "/api/v4/projects?name=blort&path=blort&issues_enabled=false&jobs_enabled=false&wiki_enabled=false&visibility=internal&approvals_before_merge=1&namespace_id=9" for IP_ADDRESS_1 at 2017-09-21 21:43:36 +0000
Started POST "/api/v4/projects?name=blort&path=blort&issues_enabled=false&jobs_enabled=false&wiki_enabled=false&visibility=internal&approvals_before_merge=1&namespace_id=9" for IP_ADDRESS_2 at 2017-09-21 21:43:36 +0000
Unable to save project. Error: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_routes_on_path"
DETAIL: Key (path)=(something/blort) already exists.
: INSERT INTO "routes" ("source_type", "path", "name", "source_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"
IP_ADDRESS_2 - - [21/Sep/2017:21:43:36 +0000] "POST /api/v4/projects?name=blort&path=blort&issues_enabled=false&jobs_enabled=false&wiki_enabled=false&visibility=internal&approvals_before_merge=1&namespace_id=9 HTTP/1.1" 201 4 "-" "org.gitlab.api.GitlabAPI/[version]"
IP_ADDRESS_1 - - [21/Sep/2017:21:43:47 +0000] "POST /api/v4/projects?name=blort&path=blort&issues_enabled=false&jobs_enabled=false&wiki_enabled=false&visibility=internal&approvals_before_merge=1&namespace_id=9 HTTP/1.1" 201 1233 "-" "org.gitlab.api.GitlabAPI/[version]"
Results of GitLab environment info
9.3.9-ee.