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

Add cleanup to SimpleEventIsolation #1032

Open
wants to merge 4 commits into
base: dev-3.x
Choose a base branch
from

Conversation

andrew000
Copy link
Contributor

Description

Cleaunp will clear unused locks to prevent memory overflow.

❗️ MUST BE REVIEWED ❗️

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

  1. pytest .\tests\test_fsm\storage\ -vv -s --redis redis://localhost:6379/0
  2. I use these named locks (and cleaunup) in the KusBot project and have already tested it on highload.

Test Configuration

  • Operating system: Windows 10 x64
  • Python version: e.g. 3.9

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works as expected
  • New and existing unit tests pass locally with my changes
  • My changes generate no new warnings or errors
  • My changes are compatible with minimum requirements of the project
  • I have made corresponding changes to the documentation

cleaunp will clear unused locks to prevent memory overflow
@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Oct 19, 2022
@github-actions
Copy link

github-actions bot commented Oct 19, 2022

✔️ Changelog found.

Thank you for adding a description of the changes

@evgfilim1 evgfilim1 requested a review from a team October 19, 2022 18:16
@JrooTJunior
Copy link
Member

@evgfilim1, should not be reviewed until changelog is added.

@evgfilim1 evgfilim1 removed the request for review from a team October 19, 2022 18:25
@andrew000
Copy link
Contributor Author

@evgfilim1, should not be reviewed until changelog is added.

My bad) I always forget to do it)

@codecov
Copy link

codecov bot commented Oct 25, 2022

Codecov Report

Merging #1032 (7f7c182) into dev-3.x (01028f1) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1032   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          302       302           
  Lines         8140      8165   +25     
=========================================
+ Hits          8140      8165   +25     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiogram/fsm/storage/base.py 100.00% <100.00%> (ø)
aiogram/fsm/storage/memory.py 100.00% <100.00%> (ø)
aiogram/types/message.py 100.00% <0.00%> (ø)

@evgfilim1 evgfilim1 requested a review from a team November 5, 2022 12:51
@@ -91,6 +91,8 @@ async def close(self) -> None: # pragma: no cover


class BaseEventIsolation(ABC):
_locks: Dict[Hashable, Any]
Copy link
Member

Choose a reason for hiding this comment

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

Why this attribute is added to the base class?
This attribute is needed only for in-memory events isolation

async def close(self) -> None:
self._locks.clear()

def _cleanup(self, key: Hashable) -> None:
if self._locks[key]._waiters is None: # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

getting access to the protected attribute is a bad decision, but you can inherit from the base class and add the necessary public attribute, for example:

from asyncio import Lock, Future
from typing import Optional, Deque


class _SimpleEventIsolationLock(Lock):
    _waiters: Optional[Deque[Future]] = None

    @property
    def has_waiters(self) -> bool:
        return bool(self._waiters)

or implement the dunder method __bool__ and use lock directly in the conditions



@pytest.mark.parametrize("isolation", [pytest.lazy_fixture("redis_isolation")])
class TestRedisIsolation:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think so the original test should be separated into three, but you can implement new one test that prove your changes, it can alsobe test that you already implement here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issue or PR for stable 3.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants