Skip to content

Prevent duplicate plugin registrations #3879

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

Closed
wants to merge 1 commit into from
Closed

Conversation

kamalca
Copy link
Collaborator

@kamalca kamalca commented Jun 20, 2025

Plugins were getting registered every time the file was being imported.

Plugins were getting registered every time the file was being imported.
@squirrelsc
Copy link
Member

@LiliDeng LGTM

@squirrelsc
Copy link
Member

I'm ok with this change. But I remembered I handled the import logic, only UT may import the same module twice. The normal LISA process only import once.

@kamalca
Copy link
Collaborator Author

kamalca commented Jun 21, 2025

I'm ok with this change. But I remembered I handled the import logic, only UT may import the same module twice. The normal LISA process only import once.

@squirrelsc I’m not sure what is going on, but when I was testing the Azure Container Policy extension the Node Hook was being added nearly 3000 times.

@squirrelsc squirrelsc requested a review from Copilot June 23, 2025 19:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the issue of duplicate plugin registrations by adding conditional checks before registering plugin implementations.

  • Ensures Azure, Node, and Environment hook implementations are registered only once.
  • Introduces a registration guard check in three different modules.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
lisa/sut_orchestrator/azure/hooks.py Registers AzureHookSpecDefaultImpl only if not already registered.
lisa/node.py Registers NodeHookImpl only if not already registered.
lisa/environment.py Registers EnvironmentHookImpl only if not already registered.

Comment on lines +113 to +114
if not plugin_manager.is_registered(AzureHookSpecDefaultImpl):
plugin_manager.register(AzureHookSpecDefaultImpl())
Copy link
Preview

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

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

Consider refactoring the duplicate registration guard logic into a shared helper function to improve maintainability and reduce code repetition across hook registrations.

Suggested change
if not plugin_manager.is_registered(AzureHookSpecDefaultImpl):
plugin_manager.register(AzureHookSpecDefaultImpl())
register_hook_if_not_registered(plugin_manager, AzureHookSpecDefaultImpl)

Copilot uses AI. Check for mistakes.

@@ -1231,7 +1231,8 @@ def get_node_information(self, node: Node) -> Dict[str, str]:


plugin_manager.add_hookspecs(NodeHookSpec)
plugin_manager.register(NodeHookImpl())
if not plugin_manager.is_registered(NodeHookImpl):
Copy link
Preview

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

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

Consider refactoring the plugin registration check into a common utility function, as the same pattern is used in multiple modules.

Copilot uses AI. Check for mistakes.

Comment on lines +586 to +587
if not plugin_manager.is_registered(EnvironmentHookImpl):
plugin_manager.register(EnvironmentHookImpl())
Copy link
Preview

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

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

To reduce code duplication, consider extracting the conditional registration logic into a shared method that can be reused across different hook implementations.

Suggested change
if not plugin_manager.is_registered(EnvironmentHookImpl):
plugin_manager.register(EnvironmentHookImpl())
register_hook_implementation(EnvironmentHookImpl)

Copilot uses AI. Check for mistakes.

@kamalca kamalca closed this Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants