Linux – Failing SSHFS connection drags down the system

linuxmountsshsshfsUbuntu

From time to time my sshfs mount fails.

All programs using the mount freeze when it happens. I can't even ls anything or use nautilus.

Is there a way to find out what's the cause and how to handle it?

I've noticed regular SSH sessions to the server get their fair share of Write failed: broken pipe disconnects, too.

If I wait long enough (and I'm talking about 20-ish minutes, here) it will auto reconnect and things start working again.

Best Answer

The best method would probably be, presuming the mount point is /mnt/sshfs, to run the following:

umount -l /mnt/sshfs

This is a "lazy" unmount, and can only be run as root. It will immediately umount the sshfs file system and let the kernel clean up the mess after. Be careful not to tab complete it as there's the risk you'll get a freeze if you hit tab once too many times and it tries reading within the mount point!

Give it a min, and you should safely be able to remount the file system again.

Try adding "-o ServerAliveInterval=30" to your sshfs command and see if it stops the freezes. It basically just forces the ssh client to send a packet every 30 seconds to say it's still there. You can also add it to your .ssh/config by adding a line like follows:

ServerAliveInterval 30

I'm not 100% sure if sshfs reads the .ssh/config file though.