[mysql] 2017/12/23 11:09:37 packets.go:141: write tcp 127.0.0.1:20630->127.0.0.1:3306: write: broken pipe

4,709 views
Skip to first unread message

jobs jobs

unread,
Dec 23, 2017, 8:23:21 AM12/23/17
to golang-nuts
how to fix it?

Justin Israel

unread,
Dec 23, 2017, 3:13:28 PM12/23/17
to jobs jobs, golang-nuts


On Sun, Dec 24, 2017, 2:22 AM jobs jobs <sean...@gmail.com> wrote:
how to fix it?


2017/12/23 11:09:37 packets.go:141: write tcp 127.0.0.1:20630->127.0.0.1:3306: write: broken pipe

You haven't provided any information or code, so anyone offering help is only going to be guessing.
Try and figure out if you are using a connection after it has been closed by the server.  Are you checking all errors from your calls? 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan Mladenovic

unread,
Dec 24, 2017, 4:23:54 PM12/24/17
to golang-nuts
Write:broken pipe is usually an indication that an idle connection has been closed by the server. 

There is an  API in database/sql package for this reason.
See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime


Assuming you are using MySQL, MariaDB, you can read current timeout settings using command 


show variables like '%timeout%';
And the result will look lise this:

+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 5        |
| deadlock_timeout_long       | 50000000 |
| deadlock_timeout_short      | 10000    |
| delayed_insert_timeout      | 300      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 28800    |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| slave_net_timeout           | 3600     |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 28800    |
+-----------------------------+----------+


In this case, the interactive_timeout  value is basically idle connection timeout. 

After 28800 seconds of inactivity, the server will automatically close the connection.


To prevent further errors set connection lifetime to value less than configured.


eg. db.SetConnMaxLifetime(time.Second * 14400)

Naoki INADA

unread,
Dec 25, 2017, 1:40:02 AM12/25/17
to golang-nuts


To prevent further errors set connection lifetime to value less than configured.


eg. db.SetConnMaxLifetime(time.Second * 14400)




Thanks, but I (go-sql-driver/mysql maintainer) recommend 10~60 sec
rather than 1/2 of wait_timeout.

wait_timeout is not the only reason which close TCP connection.
TCP connection may be killed by various reasons.  (OS, router, etc...)

When people ask this question, they doesn't have enough skill to
check all possibilities by themselves.
On the other hand, 10sec is large enough to reduce overhead of
reconnection.

Anuj Agrawal

unread,
Dec 27, 2017, 8:25:44 PM12/27/17
to golang-nuts
I am seeing similar logs even after I add db.SetConnMaxLifetime(10 * time.Second). 


Any suggestions on how to debug further?

jobs jobs

unread,
Jan 6, 2018, 2:59:19 AM1/6/18
to golang-nuts
Thanks all answers!

在 2017年12月23日星期六 UTC+8下午9:23:21,jobs jobs写道:
how to fix it?
Reply all
Reply to author
Forward
0 new messages