fix race conditions on lb weight update
This commit is contained in:
parent
c18fc2a76c
commit
b3b7e427e7
@ -329,6 +329,9 @@ class OManager:
|
|||||||
old_weights = []
|
old_weights = []
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
if self.lb1_pm.pid==0 or self.lb2_pm.pid==0:
|
||||||
|
# pid not acquired yet, wait a bit more
|
||||||
|
await asyncio.sleep(3)
|
||||||
#print("calculating weights")
|
#print("calculating weights")
|
||||||
new_weights = self.calc_weights()
|
new_weights = self.calc_weights()
|
||||||
#print("finished calc")
|
#print("finished calc")
|
||||||
|
|||||||
@ -59,8 +59,8 @@ class ProcessManager:
|
|||||||
stderr=asyncio.subprocess.PIPE)
|
stderr=asyncio.subprocess.PIPE)
|
||||||
logging.info(f"Process started, cmd: {self.cmd}")
|
logging.info(f"Process started, cmd: {self.cmd}")
|
||||||
self.proc = proc
|
self.proc = proc
|
||||||
for _ in range(3):
|
for _ in range(5):
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(0.2)
|
||||||
got_pid = False
|
got_pid = False
|
||||||
try:
|
try:
|
||||||
PID = int(open(pid_fp, "r").read())
|
PID = int(open(pid_fp, "r").read())
|
||||||
@ -106,7 +106,7 @@ class ProcessManager:
|
|||||||
self.task.cancel()
|
self.task.cancel()
|
||||||
if self.pid:
|
if self.pid:
|
||||||
try:
|
try:
|
||||||
os.kill(self.pid, signal.SIGINT)
|
os.kill(self.pid, signal.SIGTERM) # SIGINT was not enough to kill the go process...
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.warning(f"kill failed: {err}")
|
logging.warning(f"kill failed: {err}")
|
||||||
self.pid = 0
|
self.pid = 0
|
||||||
@ -114,7 +114,8 @@ class ProcessManager:
|
|||||||
|
|
||||||
def signal(self, signal):
|
def signal(self, signal):
|
||||||
if self.state == ProcessManagerState.RUNNING:
|
if self.state == ProcessManagerState.RUNNING:
|
||||||
os.kill(self.pid, signal)
|
if self.pid!=0: # race condition possible when the pid has not been acquired
|
||||||
|
os.kill(self.pid, signal)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user