MySQL Broken Pipe

I logged into my Ubuntu server and saw the console printed out that MySQL complaining about “broken pipe” in the packet.go line 118. I am using the Go-sql-driver.

What does this mean?

It means your mysql server closed the connection from its side. Check your mysql error logs they may give more information.

it’s always a good idea to put some more informations about your error. logs,errors messages, maybe some piece of code. as @dfc says more times here, don’t forget to check or log your own go program errors because seems to be a common mistake.

[MySQL] 2016/03/04 22:57:38 packets.go:118: write tcp 127.0.0.1:55600->IP Hidden
:port hidden: write: broken pipe
[MySQL] 2016/03/04 22:57:38 packets.go:118: write tcp 127.0.0.1:55600->IP Hidden
:port hidden: write: broken pipe
[MySQL] 2016/03/04 22:57:38 packets.go:118: write tcp 127.0.0.1:55600->IP Hidden
:port hidden: write: broken pipe
[MySQL] 2016/03/04 22:57:38 packets.go:118: write tcp 127.0.0.1:55600->IP Hidden
:port hidden: write: broken pipe
[MySQL] 2016/03/04 22:57:38 packets.go:118: write tcp 127.0.0.1:55600->IP Hidden
:port hidden: write: broken pipe

I checked the mysql logs but I didn’t see anything in that was out of the ordinary. My other go logs just reported http2/http errors which I don’t think are related to the database.

You will probably have to increase the verbosity of your myql severs logging.

take a look here and here

Based on what people are saying in the github issues, it appears I have idle connections. One guy said the problem was fixed by setting idle connections to zero: db.SetMaxIdleConns(0)

To give more info on how I setup my MySQL with my Go application, I only open the database connection once and I never close it as the golang.org guide says:
“It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.”

When people visit my site and interact it with, it connects to the database and it creates database connections which eventually become idle as nobody is using it. Will I suffer a performance penalty if I set Max idle connections to zero?

from golang documentation of SetMaxIdleConns

If n <= 0, no idle connections are retained.

i understand that no performance problems can appear if you set to 0.

Of course performance problems can appear. Since the package won’t retain any connections and open new one each time. If you are in local the impact should be quite mostly invisible. But if you are connecting to a remote database, the impact could become visible.

About the broken pipe problem, I seem to remember that if you don’t read all the data you requested in a query (or close that sql.Rows) then the connection will stay blocked and won’t be reused. At some point, mysql will drop it. I’m playing by memory here so I’m not a 100% sure. But you should ensure you always read the data from your queries. Adding LIMIT statements if required.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.