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

[Components] Suspicious self.release(RESTComponent) #6362

Closed
drew2a opened this issue Sep 24, 2021 · 1 comment
Closed

[Components] Suspicious self.release(RESTComponent) #6362

drew2a opened this issue Sep 24, 2021 · 1 comment
Assignees

Comments

@drew2a
Copy link
Contributor

drew2a commented Sep 24, 2021

During the refactoring (#6335), we found few suspicious places that can indicate potential problems:

Why they are suspicious? Because they call self.release(RESTComponent) manually, but this operation should be performed automatically during Session.shutdown():

class Session:
    async def shutdown(self):
        await gather(*[create_task(component.stop()) for component in self.components.values()])


class Component:
    async def stop(self):
        self.logger.info("Waiting for other components to release me")
        await self.unused.wait()
        self.logger.info("Component free, shutting down")
        await self.shutdown()
        self.stopped = True
        for dep in list(self.components_used_by_me):
            self._release_instance(dep)
        self.logger.info("Component free, shutting down")
    
    async def release_component(self, dependency: Type[T]):
        dep = dependency.instance()
        if dep:
            self._release_instance(dep)

    def _release_instance(self, dep: Component):
        assert dep in self.components_used_by_me
        self.components_used_by_me.discard(dep)
        dep.in_use_by.discard(self)
        if not dep.in_use_by:
            dep.unused.set()
@drew2a drew2a added this to the Backlog milestone Sep 24, 2021
@kozlovsky
Copy link
Contributor

Fixed in #6381 (a5c774a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants