-
Notifications
You must be signed in to change notification settings - Fork 43
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
[WRK-200] memory snapshot causes clientclosed error for webapp #2367
Merged
thundergolfer
merged 5 commits into
main
from
jonathon/wrk-200-memory_snapshot-causes-clientclosed-error-for-webapp
Oct 22, 2024
+15
−5
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc10a4e
add debug logging
thundergolfer 9f80421
more debug logging
thundergolfer a482afc
fix: UnaryUnaryWrapper captures client ref which becomes stale
thundergolfer 6569f79
fix: so does UnaryStreamWrapper
thundergolfer c561893
Merge branch 'main' into jonathon/wrk-200-memory_snapshot-causes-clie…
thundergolfer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ async def _open(self): | |
self._owner_pid = os.getpid() | ||
|
||
async def _close(self, prep_for_restore: bool = False): | ||
logger.debug(f"Client ({id(self)}): closing") | ||
self._closed = True | ||
await self._cancellation_context.__aexit__(None, None, None) # wait for all rpcs to be finished/cancelled | ||
if self._channel is not None: | ||
|
@@ -156,7 +157,7 @@ async def _close(self, prep_for_restore: bool = False): | |
|
||
async def _init(self): | ||
"""Connect to server and retrieve version information; raise appropriate error for various failures.""" | ||
logger.debug("Client: Starting") | ||
logger.debug(f"Client ({id(self)}): Starting") | ||
_check_config() | ||
try: | ||
req = empty_pb2.Empty() | ||
|
@@ -302,7 +303,7 @@ async def _call_safely(self, coro, readable_method: str): | |
|
||
if self.is_closed(): | ||
coro.close() # prevent "was never awaited" | ||
raise ClientClosed() | ||
raise ClientClosed(id(self)) | ||
|
||
current_event_loop = asyncio.get_running_loop() | ||
if current_event_loop == self._cancellation_context_event_loop: | ||
|
@@ -312,7 +313,7 @@ async def _call_safely(self, coro, readable_method: str): | |
return await self._cancellation_context.create_task(coro) | ||
except asyncio.CancelledError: | ||
if self.is_closed(): | ||
raise ClientClosed() from None | ||
raise ClientClosed(id(self)) from None | ||
raise # if the task is cancelled as part of synchronizer shutdown or similar, don't raise ClientClosed | ||
else: | ||
# this should be rare - mostly used in tests where rpc requests sometimes are triggered | ||
|
@@ -406,6 +407,9 @@ async def __call__( | |
timeout: Optional[float] = None, | ||
metadata: Optional[_MetadataLike] = None, | ||
) -> ResponseType: | ||
if self.client._snapshotted: | ||
logger.debug(f"refreshing client after snapshot for {self._wrapped_method_name}") | ||
self.client = await _Client.from_env() | ||
return await self.client._call_unary(self._wrapped_method_name, req, timeout=timeout, metadata=metadata) | ||
|
||
|
||
|
@@ -426,5 +430,8 @@ async def unary_stream( | |
request, | ||
metadata: Optional[Any] = None, | ||
): | ||
if self.client._snapshotted: | ||
logger.debug(f"refreshing client after snapshot for {self._wrapped_method_name}") | ||
self.client = await _Client.from_env | ||
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. from_env is a method that needs to be called ( |
||
async for response in self.client._call_stream(self._wrapped_method_name, request, metadata=metadata): | ||
yield response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Having the object ID logged helps track the usage of fresh vs. stale clients when debugging snapshot issues.
Instead of having to catch stale
client
objects and refresh them it'd be better if the client object itself could catch that it was stale and refresh itself. If this could work then we could remove all current (and future)if self.client._snapshotted
type checks.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.
Yeah I agree, we should make the client itself detect this, which should be doable through the
_call_unary
and_call_stream
methods on it which all RPC methods should be going via now