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

Fix Connection Unavailable Error #413

Merged
merged 2 commits into from Nov 21, 2023
Merged

Fix Connection Unavailable Error #413

merged 2 commits into from Nov 21, 2023

Conversation

darunrs
Copy link
Collaborator

@darunrs darunrs commented Nov 18, 2023

So after a lot of testing, I found the problem. It turns out that the lazy loading implementation I used for context.db was set up so that any calls to a db function would first check if the dmlHandler exists (Load on access). If not, then instantiate it. This is helpful for situations where the functions aren't used. However, this had a side effect: If a bunch of db function calls come in simultaneously, they will all poll dmlHandler and see it is uninitialized and all try and create a new one. Each initialization will try to create a pool with 10 available clients. And then all of them will create at least one client each. This will exhaust the clients very quick if there's enough of them. Changing it so that the dmlHandler is lazy loaded immediately instead. And on access, it will await its completion before calling any functions. This ensures there is no more than 1 client active for that invocation. I wrote a test as well which tries 100 simultaneous calls and verified 1 pool is created.

Transaction Support can come next, now that the pooling works correctly now.

@darunrs darunrs marked this pull request as ready for review November 18, 2023 00:35
@darunrs darunrs requested a review from a team as a code owner November 18, 2023 00:35
Copy link
Collaborator

@morgsmccauley morgsmccauley left a comment

Choose a reason for hiding this comment

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

Can you please link the relevant issue

@darunrs darunrs linked an issue Nov 21, 2023 that may be closed by this pull request
@darunrs darunrs merged commit 517616a into main Nov 21, 2023
5 checks passed
@darunrs darunrs deleted the singleConnection branch November 21, 2023 18:30
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.

Support Transactions for Indexer Code Execution
2 participants