fix race condition causing initialize_swap_manager assert to fail by waiting for trigger_pairs_updated_threadsafe to set the is_initialized event before returning if it is not running on the aio loop
This commit is contained in:
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Optional, Dict, Union, Sequence, Tuple, Iterab
|
||||
from decimal import Decimal
|
||||
import math
|
||||
import time
|
||||
import concurrent.futures
|
||||
|
||||
import attr
|
||||
import aiohttp
|
||||
@@ -952,12 +953,19 @@ class SwapManager(Logger):
|
||||
self.trigger_pairs_updated_threadsafe()
|
||||
|
||||
def trigger_pairs_updated_threadsafe(self):
|
||||
future = concurrent.futures.Future()
|
||||
def trigger():
|
||||
self.is_initialized.set()
|
||||
self.pairs_updated.set()
|
||||
self.pairs_updated.clear()
|
||||
loop = get_asyncio_loop()
|
||||
loop.call_soon_threadsafe(trigger)
|
||||
future.set_result(None)
|
||||
asyncio_loop = get_asyncio_loop()
|
||||
if get_running_loop() == asyncio_loop:
|
||||
trigger() # this is running on the asyncio event loop
|
||||
else:
|
||||
asyncio_loop.call_soon_threadsafe(trigger)
|
||||
# block until the event loop has run the trigger function
|
||||
_ = future.result()
|
||||
|
||||
def server_maybe_trigger_liquidity_update(self) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user