Answer the question
In order to leave comments, you need to log in
Golang mysql: Invalid Connection?
There is a web application that works with the database through this driver https://github.com/go-sql-driver/mysql
Everything works OK, but as soon as I submit load testing to several threads (10+) with more than 2 open database connections (DB.SetMaxOpenConns https://golang.org/pkg/database/sql/#DB.SetMaxOpen... , then errors start to fall
statement.go:24: Invalid Connection
mysql> show variables like "max_connections";
Answer the question
In order to leave comments, you need to log in
Tracing the chain through the documentation
1. https://github.com/go-sql-driver/mysql is used in conjunction with the standard https://golang.org/pkg/database/sql/
2. found in https://golang.org /pkg/database/sql/ function
3. we see that the result is *Rows, we find this structure and by studying we find the function
4. we see exactly the same function in Stmt
5. we conclude that it is necessary to close connections, in certain cases, forcibly
A similar question was on toster.ru already twice.
Here you can read a discussion about the features of working with MySQL in Golang: https://toster.ru/answer?answer_id=685014#comments...
Useful links for those who want to understand the issue:
4gophers.ru/article/go- i-sql-bazy-dannyh
go-database-sql.org/surprises.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question