1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00

fix(vrtManager): a request whose read of other hosts fails counts on its host again

other_hosts counted the request on its own host again only when the
block ended normally: a quota check that raised left the request
counted on the other host while it went on with its own. The count is
now restored however the block ends.
This commit is contained in:
catborise 2026-11-05 08:49:17 +03:00
parent d4b9edc3e5
commit 3c51602652
2 changed files with 15 additions and 4 deletions

View file

@ -147,9 +147,11 @@ def other_hosts():
then goes on with the host it used before, through the objects it kept:
the request counts on that host again after the block (HOST_REQUESTS)."""
held = getattr(_request, "held", None)
yield
if held is not None:
_count_on(held)
try:
yield
finally:
if held is not None:
_count_on(held)
request_started.connect(_request_started, dispatch_uid="vrtManager.connection.request_started")

View file

@ -1,5 +1,6 @@
"""Reachability probe and connections that do not block each other."""
import contextlib
import os
import socket
import threading
@ -296,11 +297,19 @@ class HostRequestsTestCase(unittest.TestCase):
self.assertEqual(self.request("h") + self.request("h"), [])
def test_a_request_back_from_other_hosts_counts_on_its_own_again(self):
self.back_from_other_hosts(fails=False)
def test_a_request_back_from_other_hosts_that_failed_counts_on_its_own_again(self):
self.back_from_other_hosts(fails=True)
def back_from_other_hosts(self, fails):
def run():
request_started.send(sender=None)
self.manager.get_connection("h", "u", "p", CONN_TCP)
with connection.other_hosts():
with contextlib.suppress(RuntimeError), connection.other_hosts():
self.manager.get_connection("g", "u", "p", CONN_TCP)
if fails:
raise RuntimeError("the other host's read failed")
back.set()
self.done.wait(5)
request_finished.send(sender=None)