Skip to content

Goroutine leak when dial err in go1.8 #626

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

Closed
qw4990 opened this issue Jun 28, 2017 · 4 comments · Fixed by #627
Closed

Goroutine leak when dial err in go1.8 #626

qw4990 opened this issue Jun 28, 2017 · 4 comments · Fixed by #627

Comments

@qw4990
Copy link

qw4990 commented Jun 28, 2017

Issue description

Goroutine leak when dial err in go1.8

Example code

package main

import (
	"fmt"
	"log"
	"net/http"
	_ "net/http/pprof"
	"time"

	"github.com/go-sql-driver/mysql"
)

func main() {
	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()

	for i := 0; i < 100; i++ {
		var driver mysql.MySQLDriver
		_, err := driver.Open("USER:PASSWORD_HERE@wrong(127.0.0.1:3306)/DATABASE?charset=utf8&parseTime=True&loc=Local")
		fmt.Println(err)
	}

	time.Sleep(time.Hour * 5)
}

Error log

When you run the code above and access http://127.0.0.1:6060/debug/pprof/goroutine?debug=1;

You can see there are 100 leaked goroutines:

100 @ 0x102df2a 0x103d014 0x103bc7c 0x132e738 0x1059b61
#	0x132e737	github.com/go-sql-driver/mysql.(*mysqlConn).startWatcher.func1+0x287	/Users/zhangyuanjia/Work/src/github.com/go-sql-driver/mysql/connection_go18.go:189

Configuration

Driver version (or git SHA): 8fefef0

Go version: go1.8.1 darwin/amd64

Server version: MySQL 5.6

Server OS: OS X

shogo82148 added a commit to shogo82148/mysql that referenced this issue Jun 28, 2017
shogo82148 added a commit to shogo82148/mysql that referenced this issue Jun 28, 2017
@qw4990
Copy link
Author

qw4990 commented Jun 28, 2017

Fixed in #627

@qw4990 qw4990 closed this as completed Jun 28, 2017
julienschmidt pushed a commit that referenced this issue Jul 3, 2017
@neyao
Copy link

neyao commented Aug 9, 2018

Hi @qw4990
I am a golang engeer in Alibaba. We found our procss hang on execute sql, looks like the same issue as this one.

enviroment:
go version go1.9.2 linux/amd64
CentOS 6.6 LInux 4.4.88-1.el7.elrepo.x86_64

We found our process hang in sql execute, and there are lots of below logs in pprof full stack trace:

goroutine 340 [select, 167 minutes]:
github.com/go-sql-driver/mysql.(*mysqlConn).startWatcher.func1(0xc420173560, 0xc4208640c0, 0xc4203bcde0)
	github.com/go-sql-driver/mysql/connection_go18.go:182 +0xf8
created by github.com/go-sql-driver/mysql.(*mysqlConn).startWatcher
	github.com/go-sql-driver/mysql/connection_go18.go:179 +0xce

There is 452 times such logs in full stack dump logs, and our MaxOpenConns is 512

@methane
Copy link
Member

methane commented Aug 9, 2018

We found our process hang in sql execute,

What is stacktrace for them?

and there are lots of below logs in pprof full stack trace:

It is normal, not a hung.

@neyao
Copy link

neyao commented Aug 12, 2018

Thank you methane, our problem solved!

We finally found the reason why the process hung, it was a rookie mistake, we used mysql.Query() to execute update sql and rows not closed, which is exacly the "BAD" usage of this article: http://go-database-sql.org/modifying.html

There was lots of this kind of stacktrace like that:
goroutine 337 [select, 4 minutes]: database/sql.(*Rows).awaitDone(0xc420352980, 0xc8eba0, 0xc42046d340, 0x0, 0x0) golang/go/src/database/sql/sql.go:2606 +0xf3 created by database/sql.(*Rows).initContextClose golang/go/src/database/sql/sql.go:2594 +0x9c

Thanks all anyway.

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 a pull request may close this issue.

3 participants