Site icon Dhanendran's Blog

packet_write_wait: Connection to XXX : Broken pipe

When you are connected to the remote machine or server you tend to get this error. It will be very hard when we are importing large database into the server. There are few things we can do to speed up database importing process, but with all those settings if we end up in getting this connection error will make you mad.

packet_write_wait: Connection to XXX port XX : Broken pipe

Why this error?

This error will occur when you are not doing any interaction with the terminal which you used to SSH into the server. The connection will be terminated as it is idle for long time.

How to fix?

To fix this you need to keep an eye on the terminal and hit enter every few seconds.

Lol 😂 that’s not we are going to do.

We need to add few configs to keep pinging the server after a set of defined time. To add these configs we need to have a write permission to ~/.ssh/config file. If this file is not exist, you can create one.

ServerAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.

ServerAliveCountMax

Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session.

Host *
  ServerAliveInterval 30
  ServerAliveCountMax 10

So the above code will send a ping to server every 30 seconds and it will repeat the process for 10 times. So your connection will not be lost.

tada…

Exit mobile version