-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 for MySQL Pooling Async Bug #1710
Comments
Might not be the optimum way but thus is how I solved it:
I saved the returned Promise from createPool() and added await for it before every query. Not the prettiest solution but is there any better way? |
@Antzy 👋 Thanks for raising the issue. We'll fix it! |
Thanks for raising the issue! I think using a middleware function to ensure pool creation might be a cleaner approach. The problem I see is that even if we await the promise to create the pool before each query, if table creation hasn't completed before those other queries, the other queries will fail. I think we should actually be awaiting the promise from |
Thanks for looking into this. My schema is pretty much guaranteed to be already in place, so I was await-ing pool creation before every query. But you are right, much better to await ensureSchema instead. |
The NodeJS MySQL server.js code has an async Pool creation call createPool() without any await. So when it is immediately followed by ensureSchema() which runs a query on the pool, it throws an error as the pool isn't yet created:
This is the same example on Google Cloud Docs and I assumed them to be correct and wasted 2 days on this thinking something wrong at my end. Please fix this so even any other call can ensure that pool object is properly created before call.
Link to code:
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/cloud-sql/mysql/mysql/server.js
The text was updated successfully, but these errors were encountered: