Skip to content

packets.go:122: closing bad idle connection: EOF #1120

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
zhangjie2012 opened this issue Jun 1, 2020 · 9 comments
Closed

packets.go:122: closing bad idle connection: EOF #1120

zhangjie2012 opened this issue Jun 1, 2020 · 9 comments

Comments

@zhangjie2012
Copy link

zhangjie2012 commented Jun 1, 2020

Issue description

run sql statement, always print in sql package :

[mysql] 2020/06/01 18:13:51 packets.go:122: closing bad idle connection: EOF
[mysql] 2020/06/01 18:13:51 connection.go:158: driver: bad connection

but, sql call method not return error, look like sql statement run success.

Example code

Error log

time="2020-06-01T16:42:08+08:00" level=trace msg="insert database success, timestamp=1591000928549, source=test, operator=""
[mysql] 2020/06/01 17:50:17 packets.go:122: closing bad idle connection: EOF
[mysql] 2020/06/01 17:50:17 connection.go:158: driver: bad connection
time="2020-06-01T17:50:18+08:00" level=trace msg="insert database success, timestamp=1591005017994, source=test, operator=""
time="2020-06-01T17:51:09+08:00" level=trace msg="insert database success, timestamp=1591005069404, source=test, operator=""
time="2020-06-01T17:56:18+08:00" level=trace msg="insert database success, timestamp=1591005378412, source=test, operator=""
time="2020-06-01T17:56:34+08:00" level=trace msg="insert database success, timestamp=1591005394866, source=test, operator=""
time="2020-06-01T17:58:00+08:00" level=trace msg="insert database success, timestamp=1591005480770, source=test, operator=""
time="2020-06-01T17:58:02+08:00" level=trace msg="insert database success, timestamp=1591005482072, source=test, operator=""
time="2020-06-01T17:58:02+08:00" level=trace msg="insert database success, timestamp=1591005482768, source=test, operator=""
[mysql] 2020/06/01 18:13:51 packets.go:122: closing bad idle connection: EOF
[mysql] 2020/06/01 18:13:51 connection.go:158: driver: bad connection
time="2020-06-01T18:13:51+08:00" level=trace msg="insert database success, timestamp=1591006431595, source=test, operator=""
time="2020-06-01T18:13:51+08:00" level=trace msg="insert database success, timestamp=1591006431963, source=test, operator=""
time="2020-06-01T18:13:59+08:00" level=trace msg="insert database success, timestamp=1591006439486, source=test, operator=""
time="2020-06-01T18:14:10+08:00" level=trace msg="insert database success, timestamp=1591006450099, source=test, operator=""
time="2020-06-01T18:14:15+08:00" level=trace msg="insert database success, timestamp=1591006455886, source=test, operator=""
time="2020-06-01T18:14:21+08:00" level=trace msg="insert database success, timestamp=1591006461824, source=test, operator=""
time="2020-06-01T18:14:28+08:00" level=trace msg="insert database success, timestamp=1591006468706, source=test, operator="""

Configuration

Driver version (or git SHA):

github.com/go-sql-driver/mysql v1.5.0

Go version:

1.14.2

Server version:

MySQL 5.6

Server OS:

Centor(Docker)

@methane
Copy link
Member

methane commented Jun 1, 2020

Have you configured DB.SetConnMaxLifetime?
It is almost mandatory setting.

@zhangjie2012
Copy link
Author

https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime

If d <= 0, connections are reused forever.

Look like default is reused forever ? I checked sql source code, no db.maxLifetime init code, default not zero ?

@methane
Copy link
Member

methane commented Jun 1, 2020

The default is 0. Connection is reused forever.
But your DB, OS, middleware, container, proxy, router may kill the long living connection.
So you must set the lifetime short enough.

I recommend shorter than 5min.

@zhangjie2012
Copy link
Author

Ok, I will try it later.

@thiagodamas
Copy link

@pq-dong
Copy link

pq-dong commented Jun 28, 2020

I have the same problem. The following is my version information

Driver version (or git SHA):

github.com/go-sql-driver/mysql v1.5.0

Go version:

1.12

Server version:

MySQL 5.6

Server OS:

Centor(Docker)


I switched the github.com/go-sql-driver/mysql version to 1.4.1 ,then I solved the problem

@methane
Copy link
Member

methane commented Jun 28, 2020

Please read my comments in this thread.

@mastertheknife
Copy link

Hi, i am also seeing this, i wrote about it in detail here:
golang/go#39449 (comment)

@srijan-27
Copy link

Hi, is there any possible way that I can restructure this log to my desired format?
I think that implementing Print() would be required, but couldn't do so. So, if anyone tried changing the log format, it will be helpful to me.

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

No branches or pull requests

6 participants