-
Notifications
You must be signed in to change notification settings - Fork 34
fix: resolve connection issues for aggregators on different nodes #615
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
Open
akwaed
wants to merge
1
commit into
cisco-open:main
Choose a base branch
from
akwaed:shm-extended
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ | |
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Channel manager.""" | ||
|
|
||
| import asyncio | ||
| import atexit | ||
|
|
@@ -31,17 +30,7 @@ | |
|
|
||
|
|
||
| def custom_excepthook(exc_type, exc_value, exc_traceback): | ||
| """Implement a custom exception hook. | ||
|
|
||
| NOTE: this custom version is implemented due to the following warning | ||
| message printed at the end of execution: | ||
| "Error in sys.excepthook: | ||
|
|
||
| Original exception was:" | ||
| This is caused by _inner() function in cleanup(). | ||
| A root-cause is not identified. As a workaround, this custom hook is | ||
| implemented and set to sys.excepthook | ||
| """ | ||
| """Implement a custom exception hook.""" | ||
| logger.critical( | ||
| "Uncaught exception:", exc_info=(exc_type, exc_value, exc_traceback) | ||
| ) | ||
|
|
@@ -69,7 +58,7 @@ class ChannelManager(object): | |
| def __new__(cls): | ||
| """Create a singleton instance.""" | ||
| if cls._instance is None: | ||
| logger.info("creating a ChannelManager instance") | ||
| logger.info("Creating a ChannelManager instance") | ||
| cls._instance = super(ChannelManager, cls).__new__(cls) | ||
| return cls._instance | ||
|
|
||
|
|
@@ -87,37 +76,31 @@ def __call__(self, config: Config): | |
| atexit.register(self.cleanup) | ||
|
|
||
| def _setup_backends(self): | ||
| distinct_backends = {} | ||
| distinct_backends = {} | ||
|
|
||
| for ch_name, channel in self._config.channels.items(): | ||
| # rename backend in channel config as sort to avoid confusion | ||
| sort = channel.backend | ||
| if not sort: | ||
| # channel doesn't have its own backend, nothing to do | ||
| logger.warning(f"No backend specified for channel {ch_name}.") | ||
| continue | ||
|
|
||
| if sort not in distinct_backends: | ||
| # Create a new backend instance if it doesn't exist | ||
| backend = backend_provider.get(sort) | ||
| broker_host = channel.broker_host or self._config.brokers.sort_to_host[sort] | ||
| broker_host = channel.broker_host or self._config.brokers.sort_to_host.get(sort) | ||
|
|
||
| backend.configure(broker_host, self._job_id, self._task_id) | ||
|
|
||
| distinct_backends[sort] = backend | ||
|
|
||
| # Assign the backend instance to the channel | ||
| self._backends[ch_name] = distinct_backends[sort] | ||
|
|
||
| if len(self._backends) == len(self._config.channels): | ||
| # every channel has its own backend | ||
| # no need to have a default backend | ||
| return | ||
|
|
||
| # set up a default backend | ||
| sort = self._config.backend | ||
| if sort not in distinct_backends: | ||
| self._backend = backend_provider.get(sort) | ||
| broker_host = self._config.brokers.sort_to_host[sort] | ||
| broker_host = self._config.brokers.sort_to_host.get(sort) | ||
| self._backend.configure(broker_host, self._job_id, self._task_id) | ||
| else: | ||
| self._backend = distinct_backends[sort] | ||
|
|
@@ -152,7 +135,7 @@ def join(self, name: str) -> bool: | |
| if name in self._backends: | ||
| backend = self._backends[name] | ||
| else: | ||
| logger.info(f"no backend found for channel {name}; use default") | ||
| logger.info(f"No backend found for channel {name}; using default backend.") | ||
| backend = self._backend | ||
|
|
||
| self._channels[name] = Channel( | ||
|
|
@@ -165,8 +148,6 @@ def leave(self, name): | |
| if not self.is_joined(name): | ||
| return | ||
|
|
||
| # TODO: leave() is only implemented for p2p backend; | ||
| # implement it completely for mqtt backend | ||
| self._channels[name].leave() | ||
| del self._channels[name] | ||
|
|
||
|
|
@@ -182,7 +163,6 @@ def get_by_tag(self, tag: str) -> Optional[Channel]: | |
| def get(self, name: str) -> Optional[Channel]: | ||
| """Return a channel object in a given channel name.""" | ||
| if not self.is_joined(name): | ||
| # didn't join the channel yet | ||
| return None | ||
|
|
||
| return self._channels[name] | ||
|
|
@@ -193,9 +173,9 @@ def is_joined(self, name): | |
|
|
||
| def cleanup(self): | ||
| """Clean up pending asyncio tasks.""" | ||
| logger.debug("calling cleanup") | ||
| logger.debug("Calling cleanup") | ||
| for _, ch in self._channels.items(): | ||
| logger.debug(f"calling leave for channel {ch.name()}") | ||
| logger.debug(f"Calling leave for channel {ch.name()}") | ||
| ch.leave() | ||
|
|
||
| async def _inner(backend): | ||
|
|
@@ -204,12 +184,12 @@ async def _inner(backend): | |
| try: | ||
| await task | ||
| except asyncio.CancelledError: | ||
| logger.debug(f"successfully cancelled {task.get_name()}") | ||
| logger.debug(f"Successfully cancelled {task.get_name()}") | ||
|
|
||
| logger.debug("done with cleaning up asyncio tasks") | ||
| logger.debug("Done cleaning up asyncio tasks") | ||
|
|
||
| if self._backend: | ||
| _ = run_async(_inner(self._backend), self._backend.loop()) | ||
|
|
||
| for k, v in self._backends.items(): | ||
| _ = run_async(_inner(v), v.loop()) | ||
| _ = run_async(_inner(v), v.loop()) | ||
|
Contributor
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. nit: please add a new line. |
||
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.
can you please remove these commented lines?