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

Implement a custom filtering method #737

Merged
merged 2 commits into from
Apr 22, 2024
Merged

Conversation

Adamantios
Copy link
Collaborator

Proposed changes

Implement a custom filtering method to handle RPC timeouts.

Fixes

Fixes valory-xyz/open-autonomy#2121.

Types of changes

What types of changes does your code introduce to agents-aea?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING doc
  • I am making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Lint and unit tests pass locally with my changes and CI passes too
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that code coverage does not decrease.
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

n/a

@Adamantios Adamantios added the enhancement New feature or request label Apr 19, 2024
Implement a custom filtering method to handle potential RPC timeouts or hanging.
Comment on lines +374 to +394
def rpc_call_with_timeout(func: Callable, timeout: int) -> Any:
"""Execute an RPC call with a timeout."""

with concurrent.futures.ThreadPoolExecutor(RPC_CALL_MAX_WORKERS) as executor:
# submit the function with the RPC call to the executor
future = executor.submit(func)

try:
# wait for the result with a timeout
data = future.result(timeout=timeout)
except TimeoutError:
# handle the case where the execution times out
err = f"The RPC didn't respond within {timeout} seconds."
return None, err

# check if an error occurred
if isinstance(data, str):
# handle the case where the execution fails
return None, data

return data, None

Choose a reason for hiding this comment

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

I don't understand the purpose of this method, you're creating a thread pool executor and you're only submitting one function at a time which means you're basically executing one function at a time instead of executing multiple function calls parallely

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's basically for the timeout to avoid hanging:

:param timeout: a timeout in seconds to interrupt the operation in case the RPC request hangs.

filtering_operation = self.batch_filter_wrapper(
event, match_single, match_any, to_block_adj, from_block
)
batch_result, err = rpc_call_with_timeout(filtering_operation, timeout)

Choose a reason for hiding this comment

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

See the comment above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Adamantios Adamantios merged commit 614dd04 into main Apr 22, 2024
36 checks passed
@Adamantios Adamantios deleted the feat/handle-rpc-timeouts branch April 22, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make termination more "RPC friendly"
3 participants