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

Fix/publish concurrency #1271

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fix/publish concurrency #1271

wants to merge 5 commits into from

Conversation

neolynx
Copy link
Member

@neolynx neolynx commented Apr 17, 2024

Replaces #1261

Description of the Change

Fixes #1125

This MR addresses a concurrency issue with the api/publish endpoint, where concurrent PUTs typically fail. The MR in it self is not pretty, so consider this initial state of the MR a starting point of discussion.
The commits are intentionally separated in order to make it as easy as possible to observe the failing test (and test it against other likely better code changes).

@neolynx neolynx self-assigned this Apr 18, 2024
@neolynx
Copy link
Member Author

neolynx commented Apr 20, 2024

the test t12_api:TaskAPITestParallelTasks failes with this implementation... does it need to be updated?

2024-04-20T21:03:23.8650330Z [GIN] 2024/04/20 - 21:03:23 | 202 | 12.838215884s |       127.0.0.1 | PUT      "/api/mirrors/x41qcXfiIf7ho72?_async=True"
2024-04-20T21:03:23.8662294Z Traceback (most recent call last):
2024-04-20T21:03:23.8675218Z   File "/home/runner/work/aptly/aptly/system/run.py", line 102, in run
2024-04-20T21:03:23.8676107Z     t.test()
2024-04-20T21:03:23.8676889Z   File "/home/runner/work/aptly/aptly/system/lib.py", line 178, in test
2024-04-20T21:03:23.8677717Z     self.check()
2024-04-20T21:03:23.8678774Z   File "/home/runner/work/aptly/aptly/system/t12_api/tasks.py", line 81, in check
2024-04-20T21:03:23.8680027Z     mirror_task_id, mirror_name = self._create_mirror(mirror_dist)
2024-04-20T21:03:23.8680826Z                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-20T21:03:23.8681926Z   File "/home/runner/work/aptly/aptly/system/t12_api/tasks.py", line 25, in _create_mirror
2024-04-20T21:03:23.8683079Z     self.check_equal(resp2.status_code, 409)
2024-04-20T21:03:23.8684153Z   File "/home/runner/work/aptly/aptly/system/lib.py", line 418, in check_equal
2024-04-20T21:03:23.8684851Z     self.verify_match(a, b, match_prepare=pprint.pformat)
2024-04-20T21:03:23.8685526Z   File "/home/runner/work/aptly/aptly/system/lib.py", line 469, in verify_match
2024-04-20T21:03:23.8686425Z     raise Exception("content doesn't match:\n" + diff + "\n")
2024-04-20T21:03:23.8686894Z Exception: content doesn't match:
2024-04-20T21:03:23.8687342Z --- 
2024-04-20T21:03:23.8687629Z +++ 
2024-04-20T21:03:23.8688024Z @@ -1 +1 @@
2024-04-20T21:03:23.8688566Z -202
2024-04-20T21:03:23.8688908Z +409

Create Mirror in parallel seems now to return 202, but 409 was expected.

@neolynx neolynx added the fix tests Tests are failing label Apr 20, 2024
@ramonnr
Copy link

ramonnr commented Apr 24, 2024

Sorry for the tardy response, I'll look over what happened after the rebase :)

runitonmetal and others added 5 commits April 24, 2024 17:42
This commit introduces a test which runs concurrent publishes (which
could be parallell with multiproccessing, python is fun).
The test purposly fails (at the point in history that this patch is
written) in order to make it as easy as possible to verify later patches,
which hopefully addresses concurrency problems.

The same behaviour can easily be tested outside of the system tests with
the following (or similar) shell

$ aptly serve -listen=:8080 -no-lock
$ aptly repo create create -distributions=testing local-repo
$ atply publish repo -architectures=amd64 local-repo
$ apt download aptly
$ aptly repo add local-repo ./aptly*.deb
$ for _ in $(seq 10); do curl -X PUT 127.0.0.1:8080/api/publish//testing

In the local testing perfomed (on a dual core vm) the first 1-4 jobs
would typically succeed and the rest would error out.
This commit blocks concurrent calls to RunTaskInBackground which is
intended to fix the quirky behaviour where concurrent PUT calls to
api/publish/<prefix>/<distribution> would immedietly reuturn an error.

The solution proposed in this commit is not elegant and probaly has
unintended side-effects. The intention of this commit is to highlight
the area that actually needs to be addressed.
Ideally this patch is amended or dropped entierly in favor of a better
fixup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: failures and race conditions with concurrent publish update operations
3 participants