-
Notifications
You must be signed in to change notification settings - Fork 7
fix race condition - library can become not ready before the event.wait() returns #740
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,18 +169,26 @@ async def wait_for_library_ready(self, timeout: int = None): | |
| """ | ||
| Wait for the library to be ready. | ||
|
|
||
| After the ready edge event fires, re-checks `is_ready()`; if another task | ||
| moved the library back to not-ready before this coroutine resumed, raises | ||
| instead of waiting again. | ||
|
|
||
| Args: | ||
| timeout (int): The timeout in seconds. If not provided, the default timeout is used. | ||
|
|
||
| Raises: | ||
| LibraryNotReadyError: If the library is not ready within the timeout. | ||
| LibraryNotReadyError: If the library is not ready within the timeout, or if it is | ||
| not ready when this coroutine continues after the wait. | ||
| """ | ||
| if timeout is None: | ||
| timeout = self.LibraryReadyTimeout | ||
| if self.is_ready(): | ||
| return | ||
| try: | ||
| await asyncio.wait_for(self.LibraryReadyEvent.wait(), timeout=timeout) | ||
| except asyncio.TimeoutError: | ||
| raise LibraryNotReadyError("Library is not ready yet.") | ||
| self._ensure_ready() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still feels like a one-time wait. We wake on the first ready event and then decide immediately from that one wake-up. If the goal is still “wait until ready or timeout”, I think we probably need to keep waiting when that wake turns out to be stale, instead of treating it as the final truth for readiness.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably do something like this instead, so we keep waiting until self.is_ready() is actually true, while still respecting the original timeout. |
||
|
|
||
| async def _set_ready(self, provider): | ||
| if len(self.Libraries) == 0: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fast path is good. It avoids waiting when readiness already holds at entry itself.