Skip to content

refactor: simplify scalers cache by removing getScalerBuilder method #6773

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rickbrouwer
Copy link
Contributor

@rickbrouwer rickbrouwer commented May 13, 2025

@JorTurFer mentioned in #6739:

I'm wondering if we should get rid of getScalerBuilder directly, as it uses a read mutex inside but it can return a scaler that it's immediately closed just after returning it. There are some tricky conditions, so maybe we can start with this as suggested and iterate if needed

This PR improves the scalers cache implementation by removing the getScalerBuilder method and inlining its functionality directly in the methods that need it. This is refactoring. A good check is desired :)

Checklist

Relates to #6739

@rickbrouwer rickbrouwer requested a review from a team as a code owner May 13, 2025 07:59
@rickbrouwer rickbrouwer changed the title feat: remove getScalerBuilder to avoid potential race conditions refactor: simplify scalers cache by removing getScalerBuilder method May 13, 2025
Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

I think that this makes the locks a bit more explicit, but checking the result, I don't think that refactoring the function will avoid the race condition that could be before (the case where something changes after the read lock because the write lock is signaled after checking the result of the read lock output, but I'm not sure if we should extend the read lock context either 🤔 ), so I'm not fully sure about if merging this we are improving the readability or making the code more difficult to read. @wozniakjan ?

@rickbrouwer
Copy link
Contributor Author

I think that this makes the locks a bit more explicit, but checking the result, I don't think that refactoring the function will avoid the race condition that could be before (the case where something changes after the read lock because the write lock is signaled after checking the result of the read lock output, but I'm not sure if we should extend the read lock context either 🤔 ), so I'm not fully sure about if merging this we are improving the readability or making the code more difficult to read. @wozniakjan ?

Yeah, you are right that this refactoring does not fix the underlying race condition. It keep the locks at the same boundaries. It’s more to make the code more explicit about where locks are held and removing an abstraction layer.
I think that if we also wanted to address the potential race condition, we should hold the read lock longer during operations on the scaler. But that may have performance implications.

What do you think is the best approach? I’m also fine by closing the PR.

@JorTurFer
Copy link
Member

WDYT @wozniakjan @zroubalik ?

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