Mounting sshfs on unreliable connection
Asked Answered
G

3

10

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
Gustafson answered 16/7, 2013 at 21:5 Comment(0)
T
11

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.

Trefor answered 27/10, 2014 at 9:5 Comment(0)
F
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
Fear answered 3/8, 2013 at 21:19 Comment(1)
-1... for recommending unencrypted connection over an encrypted one without any warningTrefor
M
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 [email protected]:/ "$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

Metalware answered 17/3, 2017 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.