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

Fixed state file deadlock #233

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions horizon/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ async def update_state(self) -> AsyncGenerator[PersistentState, None]:
prev_state = self._state
try:
async with self._write_lock:
await asyncio.gather(*self._tasks)
new_state = self._state.copy()
yield new_state
try:
Expand Down Expand Up @@ -196,13 +195,15 @@ def build_state_payload_sync(cls) -> dict:
return payload

async def _report(self, state: PersistentState | None = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to disable this feature with env var and enable only at will?

if state is not None:
self._state = state.copy()
config_url = f"{sidecar_config.CONTROL_PLANE}{sidecar_config.REMOTE_STATE_ENDPOINT}"
async with aiohttp.ClientSession() as session:
logger.info("Reporting status update to server...")
response = await session.post(
url=config_url,
headers={"Authorization": f"Bearer {self._env_api_key}"},
json=await PersistentStateHandler.build_state_payload(state),
json=await PersistentStateHandler.build_state_payload(),
)
if response.status != status.HTTP_204_NO_CONTENT:
logger.warning(
Expand All @@ -213,9 +214,7 @@ async def _report(self, state: PersistentState | None = None):

async def seen_sdk(self, sdk: str):
if sdk not in self._state.seen_sdks:
# ensure_future is expensive, only call it if actually needed
async with self._write_lock:
self._tasks.append(asyncio.create_task(self._report_seen_sdk(sdk)))
await self._report_seen_sdk(sdk)

async def _report_seen_sdk(self, sdk: str):
async with self._seen_sdk_update_lock:
Expand Down
Loading