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

ticket-wait <ID> should fail if another process closes it #22

Open
praiskup opened this issue Sep 18, 2019 · 1 comment
Open

ticket-wait <ID> should fail if another process closes it #22

praiskup opened this issue Sep 18, 2019 · 1 comment

Comments

@praiskup
Copy link
Owner

ssia

@praiskup
Copy link
Owner Author

praiskup commented Apr 8, 2020

Not only summary; this needs to be done by far more robust.

Since we expect in copr that even over hundred or two of clients might be concurrently
waiting for ticket resolution, we can not keep that many connections open. That said,
the ticket-wait is basically useless for copr. We could, though, do something like:

  1. actively wait on server for say 5 seconds if the ticket gets resolved that fast or not
  2. fallback to polling
  3. opt-in client side polling

The wake-up delivery is not robust either. The worst case scenario is that
the wake-up even is lost and the ticket-wait waits another 10s.

diff --git a/resallocserver/api.py b/resallocserver/api.py
index d4bcfe3..20108cd 100644
--- a/resallocserver/api.py
+++ b/resallocserver/api.py
@@ -84,18 +84,19 @@ class ServerAPI(object):
 
         with session_scope() as session:
             ticket = session.query(models.Ticket).get(ticket_id)
+            if ticket.resource:
+                return ticket.resource.data
             ticket.tid = self.my_id()
             session.add(ticket)
 
         while True:
-            with session_scope() as session:
-                ticket = session.query(models.Ticket).get(ticket_id)
-                if ticket.resource:
-                    return ticket.resource.data
-
             with self.sync.resource_ready:
+                with session_scope() as session:
+                    ticket = session.query(models.Ticket).get(ticket_id)
+                    if ticket.resource:
+                        return ticket.resource.data
                 while self.sync.resource_ready.wait(timeout=10):
-                    if self.sync.tid==self.my_id():
+                    if self.sync.tid == self.my_id():
                         break
 
 
diff --git a/resallocserver/manager.py b/resallocserver/manager.py
index 42ac5b9..288c226 100644
--- a/resallocserver/manager.py
+++ b/resallocserver/manager.py
@@ -489,8 +489,8 @@ class Manager(object):
         self.sync = sync
 
     def _notify_waiting(self, thread_id):
-        self.sync.tid = thread_id
         with self.sync.resource_ready:
+            self.sync.tid = thread_id
             self.sync.resource_ready.notify_all()
 
     def _assign_tickets(self):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant