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
SQL querying method called in two different methods makes server stops #33539
Comments
This sounds like a db locking issue. Do you close SQL.Rows? Do you defer tx.Rollback then call tx.Commit on happy path? |
Hi, Thank you for your response I do close sql.Rows like this :
And since there are only "SELECT" sql query (i.e I'm only reading the database) I believed tx.Rollback and tx.Commit were not useful, was I wrong ? |
That sounds fine then. Without seeing more real code and sql, it will be hard to help. My hunch is there is a bug somewhere in your code. This doesn't sound like a database/sql issue. |
Hi and thank you again for trying to help me ! It's a bit complex because this code wasn't written by me and I don't want it to be publicly available without the writer's approval, however I can't have it right now. But I can explain and show what it does to a certain extent.
I hope you understood me and that you will be able to help me understand, thanks again ! |
I think I can help.
The sqlProvider.Get looks odd, not the way I would recommend doing it. Ensure that s.Connections is guarded by a RWMutex. There isn't anything intrinsic to this code that would cause it to block. If you can repro, get into a blocked state then check how many open connections there are to MySQL and what state they are in. |
Hi, it's a very interesting point and I absolutely agree that the map[string]*sql.DB should be protected by a RWMutex in case of write/read. It will be changed ASAP ! However It cannot be the source of my problem because in my case I only use one SQL connection (meaning I create it the first time then reuse the same one all the time). I checked with metrics on mySQL server and there is only one open SQL connection as expected. Thanks again for your help ! |
The symptoms sound like out of available connections and the engine blocking waiting for one to free up. While details are missing, it looks to me like your code is opening a db connection in GetProducts and passes the rows to populate. This connection is still open when subsequently calling customFields which is in need of an available database connection to proceed. Until your single connection closes it'll block, but since its single threaded, it has no hope of that. Even if killed from the server, the client pool of one connection will think it's still in use. You may need to use a connection pool of multiple connections instead of a single one from the map tied to dbhost. |
Closing old issues that still have the WaitingForInfo label where enough details to investigate weren't provided. Feel free to leave a comment with more details and we can reopen. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I believe go1.12.7 is the latest release at the moment
What operating system and processor architecture are you using (
go env
)?go env
What did you do?
My problem is very specific, I was able to debug it but I am creating an issue because I want to understand why it did that and I was not able to find explanation on the internet.
Context
I created a golang webserver, in this server there are Data Access Object, which fetch data from a mySQL database. In my DAO there is a method to fetch products (GetProducts) this method calls two other methods (Properties & Populate) which both call method CustomFields (which fetch database columns names specific to the customer whom products we want)
There are multiple methods involved in this process :
DAO
Methods
Explanation
As you can see I removed a lot of code because it was just here to make you understand what's going on. There is no issue with the code and everything is working fine when I launch the server.
What did you expect to see?
A constantly working golang server
What did you see instead?
This issue is whenever is call my DAO a lot of times, about 10 requests per seconds my server is stopping. It's not dying and exiting, it's freezing and I have to relaunch it manually. This is not an infrastructure problem with the host machine or the mySQL database server.
It's due to Populate() & Properties() both calling the method CustomField(), because whenever I remove the CustomField() call in the Populate() method everything is fine. The server is working and can go up to more than 120 requests per seconds without trouble. After a lot of testing I am 100% positive that it doesn't come from anything else.
My question is : Why does calling a simple SQL query method in two different method is creating an issue ?
Thanks I hope I explained myself well and that someone will be able to help me understand what happened. If you have any questions feel free to ask
The text was updated successfully, but these errors were encountered: