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
Too many connections #111
Comments
Please take a look here: https://github.com/VividCortex/go-database-sql-tutorial Don't use .Query, use .Exec. |
Option 1: Too high concurrencyYou have too many concurrent database accesses. In this case you must manually limit the number of concurrent connections until the database/sql package provides a blocking-mechanism in a future version for that. But in many cases caching / asynchronous updates would be the better alternative. Option 2: Leaking connectionsMost probably your program is just leaking database connections. This happens if you don't close the My general advice is to use
|
I changed "db.Query()" to "db.Prepare() and db.Exec()" and that fixed my issue. Thanks for the fast, great answers. |
I got this too. var db *sql.DB func getdb() *sql.DB { func foo(db *sql.DB) { func main() { |
try go 1.3 |
and... why do you start a goroutine in main? |
sorry for my description, actually, code: func socke_server () { func main() { But, now, I use Unix domain protocol('user:pwd@unix(/tmp/mysql.sock)/'), it fixed. thanks reply |
You shouldn't do that, either - it may work, but it's slow. Put the accept-loop in main. Try the following code: func handleConnection(db *sql.DB, args...interface{}) {
// do someting.....
// db.Exec("STATEMENT", args...)
}
func main() {
db, err := sql.Open("mysql", connArgs)
if err != nil {
panic(err)
}
db.SetMaxIdleConns(100)
defer db.Close()
for {
// accept connections and pass relevant stuff to handleConnection
go handleConnection(db, nil)
}
} |
Thanks, I got it. |
I'm seeing the error message "Too man connections" when calling db.sqlDB.Query(). Before I dig further into this issue, I'm wondering if there is a known issue.
Thoughts?
013/07/23 03:05:35 yy.UpdateThingy() db.go:264 [Failed to insert record into XXXX: Error 1040: Too many connections]
I'm using go version 1.1.1:
go version go1.1.1 linux/386
I'm using the mysql driver version:
v1.0.1
MySql Version:
Server version: 5.5.22-0ubuntu1 (Ubuntu)
Here is a sample of one of my queries:
rows, err =
db.sqlDB.Query("insert into XXXX (yyyy) value (?)",
connect.ZZZZ)
if err != nil {
_ = rows.Close();
return result, err
}
_ = rows.Close();
I added "rows.Close()" hoping it would fix the issue, but no dice.
FYI, some of my queries use "rows.Scan" and some don't.
The text was updated successfully, but these errors were encountered: