Skip to content

[Bug]: 500 when requesting /api/project/:project/repos/upload_code concurrently #3731

@un-def

Description

@un-def

Steps to reproduce

# .dstack.yml
type: task
repos:
  - .
commands:
  - sleep 10
dd if=/dev/urandom of=blob bs=1M count=1
for i in {1..4}; do dstack apply --name task-$i --yes --detach & done

Actual behaviour

Only one run submitted:

dstack ps --last 4
 NAME             BACKEND       GPU  PRICE  STATUS      SUBMITTED
 task-3           ssh (remote)  -    $0     exited (0)  4 mins ago
 dev-environment  ssh (remote)  -    $0     stopped     1 hour ago
 dev-environment  ssh (remote)  -    $0     stopped     2 days ago
 dev-environment  ssh (remote)  -    $0     stopped     4 days ago

All other submissions failed with 500

Expected behaviour

No response

dstack version

0.20.15

Server logs

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/def/dev/dstack/.venv/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 545, in _prepare_and_execute
    self._rows = deque(await prepared_stmt.fetch(*parameters))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/def/dev/dstack/.venv/lib/python3.13/site-packages/asyncpg/prepared_stmt.py", line 176, in fetch
    data = await self.__bind_execute(args, 0, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/def/dev/dstack/.venv/lib/python3.13/site-packages/asyncpg/prepared_stmt.py", line 267, in __bind_execute
    data, status, _ = await self.__do_execute(
                      ^^^^^^^^^^^^^^^^^^^^^^^^
        lambda protocol: protocol.bind_execute(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            self._state, args, '', limit, True, timeout))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/def/dev/dstack/.venv/lib/python3.13/site-packages/asyncpg/prepared_stmt.py", line 256, in __do_execute
    return await executor(protocol)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "asyncpg/protocol/protocol.pyx", line 206, in bind_execute
asyncpg.exceptions.UniqueViolationError: duplicate key value violates unique constraint "uq_codes_repo_id_blob_hash"
DETAIL:  Key (repo_id, blob_hash)=(fbb27a2e-64da-48fb-99ac-8e9df39c9a6f, 770556cd8acb61ec712e9473bf7272d06d86d098f26bc9047e20fd062343267b) already exists.

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions