Prevent stuck vectors in objects._pending

This commit is contained in:
Lee Miller 2024-10-15 00:11:51 +03:00
parent 7a69dded3a
commit e5c7d77b9b
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
3 changed files with 8 additions and 1 deletions

View File

@ -472,6 +472,7 @@ class Connection(ConnectionBase):
logging.debug('%s:%s -> %s', self.host_print, self.port, obj) logging.debug('%s:%s -> %s', self.host_print, self.port, obj)
self.vectors_requested.pop(obj.vector, None) self.vectors_requested.pop(obj.vector, None)
self.vectors_to_get.discard(obj.vector) self.vectors_to_get.discard(obj.vector)
shared.objects.check(obj.vector)
if obj.is_valid(): if obj.is_valid():
shared.objects[obj.vector] = obj shared.objects[obj.vector] = obj
if ( if (

View File

@ -56,6 +56,8 @@ class Manager(threading.Thread):
outgoing_connections = 0 outgoing_connections = 0
for c in shared.connections.copy(): for c in shared.connections.copy():
if not c.is_alive() or c.status == 'disconnected': if not c.is_alive() or c.status == 'disconnected':
shared.objects.check(
*(c.vectors_to_get | c.vectors_requested.keys()))
with shared.connections_lock: with shared.connections_lock:
shared.connections.remove(c) shared.connections.remove(c)
else: else:

View File

@ -57,6 +57,11 @@ class Inventory():
expires, obj_type, version, stream, data, offset, expires, obj_type, version, stream, data, offset,
tag=tag, vector=vector) tag=tag, vector=vector)
def check(self, *vectors):
with self._lock:
for vector in vectors:
self._pending.discard(vector)
def cleanup(self): def cleanup(self):
if len(self._pending) > 100: if len(self._pending) > 100:
logging.warning( logging.warning(
@ -233,7 +238,6 @@ class Inventory():
return return
with self._lock: with self._lock:
self._last[vector] = obj self._last[vector] = obj
self._pending.discard(vector)
def __bool__(self): def __bool__(self):
if self._last: if self._last: