mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(claims): a request's claim no longer blocks once its process has ended
A request removes its transient claims in a finally. A gunicorn worker that exits past its timeout ends its other threads' requests too, and an OOM kill or a container restart ends all of them, so their claims stayed until they expired 11 minutes later. A VM delete killed this way held its compute exclusively: every VM action, job and list refresh on that compute was refused as busy, and nothing in the panel could clear it. The holder now names the installation by its node id (as the worker does), which stays the same when the container is recreated, instead of the hostname. A conflicting claim whose holder is a process of this installation that no longer runs is removed during admission. A claim of another installation, or of a PID that is in use again, still waits for its expiry.
This commit is contained in:
parent
b70b1aa877
commit
5ef2b6189b
2 changed files with 52 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""Admission writes claims only when nothing active conflicts, all or
|
||||
nothing; exclusive conflicts with any claim, shared only with exclusive."""
|
||||
|
||||
import subprocess
|
||||
from datetime import timedelta
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
|
|
@ -62,6 +63,26 @@ class AdmitTestCase(TestCase):
|
|||
claims.admit({"instance:u1": X}, holder="b")
|
||||
self.assertEqual(list(Claim.objects.values_list("holder", flat=True)), ["b"])
|
||||
|
||||
def test_a_claim_of_a_process_that_ended_does_not_block(self):
|
||||
ended = subprocess.Popen(["true"])
|
||||
ended.wait()
|
||||
node = claims._node()
|
||||
Claim.objects.create(resource="instance:u1", mode=X, holder=f"{node}:{ended.pid}:1",
|
||||
expires_at=timezone.now() + claims.TRANSIENT_TTL)
|
||||
claims.admit({"instance:u1": X}, holder="b")
|
||||
self.assertEqual(list(Claim.objects.values_list("holder", flat=True)), ["b"])
|
||||
|
||||
def test_a_claim_of_a_running_process_or_another_installation_blocks(self):
|
||||
ended = subprocess.Popen(["true"])
|
||||
ended.wait()
|
||||
for holder in (claims.holder_id(), f"other-node:{ended.pid}:1"):
|
||||
with self.subTest(holder=holder):
|
||||
Claim.objects.create(resource="instance:u1", mode=X, holder=holder,
|
||||
expires_at=timezone.now() + claims.TRANSIENT_TTL)
|
||||
with self.assertRaises(claims.Busy):
|
||||
claims.admit({"instance:u1": X}, holder="b")
|
||||
Claim.objects.all().delete()
|
||||
|
||||
def test_keys_are_canonical(self):
|
||||
self.assertEqual(claims.compute_key(3), "compute:3")
|
||||
self.assertEqual(claims.instance_key("u-1"), "instance:u-1")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue