8

I mount remote filesystem with sshfs. If the ssh connection times out it can cause other applications to hang (e.g. vim session with only local file open). It takes ~10 minutes for the system to recover. This happens even if I mount the remote filesystem read-only. Why? Is there a way to do sshfs mount so that it will not cause other applications to hang when using unreliable connection (e.g., wifi)? I don't need something robust, I just need to be able to view files on remote computer, can be read-only.

I use lubuntu 12.10.

$sshfs -V
SSHFS version 2.4
FUSE library version: 2.9.0
fusermount version: 2.9.0
using FUSE kernel interface version 7.18
John Newman
  • 193
  • 1
  • 7

3 Answers3

10

Use -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

These ServerAlive options cause the I/O errors to pop out after one minute of network outage. Without these options, processes which experience I/O hang seem to sleep indefinitely, even after the sshfs gets reconnect'ed.

kubanczyk
  • 3,448
  • 30
  • 45
1

You can play a little bit with the options of sshfs, for example, enabling the compression, the automatic reconnect and nodelay flag for tcp:

-C     equivalent to '-o compression=yes'
-o reconnect
-o workaround=LIST
    [no]nodelaysrv
              set nodelay tcp flag in ssh (default: off)

sshfs server:/srv/homes /mnt/mountpoint -C -o reconnect -o workaround=nodelaysrv

But what has give me better results is using NFS, I don't have the lags that I had with sshfs and is pretty standard in the *nix environment, you can export your directory with the read-only option giving you an extra speed. Although note that NFS is not an encrypted protocol.

Server:

# File: /etc/exports
/srv/homes    hostname1(rw,sync,no_subtree_check)    hostname2(ro,sync,no_subtree_check)

Client:

mount server:/srv/homes /mnt/mountpoint
Emil Vikström
  • 84,510
  • 15
  • 132
  • 168
rgamez
  • 44
  • 1
  • 3
1

Monitor remote host and terminate local sshfs process if you think remote side has gone. You can do it in many different ways. For instance start pinging it like that in a bash way:

mountpoint=~/mnt/google

sshfs -o reconnect,ServerAliveInterval=5,ServerAliveCountMax=3 user@google.com:/ "$mountpoint"

while :
do
  if ping -c 3 google.com
  then
    echo "google.com is still up"
  else
    # find sshfs pid
    sshfsPids=$(ps -C sshfs -f | grep "$mountpoint" | grep -v grep | awk '{print $2}' | tr '\n' ' ')
    kill -SIGTERM "$sshfsPids"
  fi 
done

If you are ok to use external watchdog approach for your connection consider this project: https://github.com/RuralYak/sshfs-watchdog which does pretty much the same but in a more sophisticated way

RuralYak
  • 11
  • 2