-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: resolve potential deadlock in AsyncInMemoryCache #4464
fix: resolve potential deadlock in AsyncInMemoryCache #4464
Conversation
916fae4
to
eb733f0
Compare
@ogabrielluiz The PR contains an error: the lock parameter cannot be removed, even though it is not used.
It will also be passed in during the call. |
Hey @dhlidongming Thanks for this fix. Maybe you could pass the lock all the way down to the |
Could also use a rentrant lock asyncio.RLock ? |
@@ -355,11 +355,7 @@ async def _clear(self) -> None: | |||
self.cache.clear() | |||
|
|||
async def upsert(self, key, value, lock: asyncio.Lock | None = None) -> None: | |||
if not lock: |
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.
Annotate the method with @override
(from typing_extensions) to solve the ARG002 rule error.
CodSpeed Performance ReportMerging #4464 will degrade performances by 15.55%Comparing Summary
Benchmarks breakdown
|
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.
LGTM
* Fix potential lock misuse and deadlock in AsyncInMemoryCache. * Recover async lock handling logic. * Remove unused lock parameter in upsert. * Fix potential lock misuse and deadlock in AsyncInMemoryCache. * Recover async lock handling logic. * Remove unused lock parameter in upsert. * Add lock parameter to prevent errors. * Fix ARG002 rule error. * Lock passed to get and set method. --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This pull request resolves potential concurrency issues in the
AsyncInMemoryCache
class.In the
upsert
function:langflow/src/backend/base/langflow/services/cache/service.py
Lines 357 to 360 in 1e4594a
if the lock parameter is not provided, the
self.lock
object is used to acquire a lock before calling the_upsert
function. Within the_upsert
function, theget
function is invoked without a lock parameter:langflow/src/backend/base/langflow/services/cache/service.py
Lines 364 to 365 in 1e4594a
which causes the
get
function to acquire theself.lock
object again, leading to a deadlock:langflow/src/backend/base/langflow/services/cache/service.py
Lines 300 to 303 in 1e4594a