2

I'm using sshfs to mount and interact with directories and files located on a remote server. The command I'm using is:

sshfs -o follow_symlinks host:dir mountpoint -o reconnect

Sometimes, after a period of inactivity, when I wake up the computer from the suspended mode, processes that use a resource on the remote server do not respond anymore. enter image description here It mainly happens for the Nautilus (Files) and can happen for Okular if an opened PDF file is located on the remote server.

Trying to kill those processes with kill -9 does not work. For example, when the Nautilus doesn't respond, here are the command I'm using to try to kill the process:

toto:~/.ssh$ ps aux | grep nautilus
toto   21435  0.4  0.3 1440760 123276 ?      Sl   09:32   1:48 /usr/bin/nautilus --gapplication-service
toto   96139  0.0  0.0   9216  2428 pts/4    S+   15:44   0:00 grep --color=auto nautilus
toto:~/.ssh$ kill -9 21435

I've learned here this is because they are in uninterruptible sleep. From this other discussion, I thought a solution was to use -o reconnect as parameter for sshfs. Unfortunately, I still get apps that do not respond after the computer wakes up.

TVG
  • 143

1 Answers1

0

I would try it with ServerAliveInterval with ServerAliveCountMax and/or ClientAliveInterval

ServerAliveInterval seems to be the most common strategy to keep a connection alive and to prevent the broken pipe problem.

What do options ServerAliveInterval and ClientAliveInterval in sshd_config do exactly?

In shell:

sshfs -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o follow_symlinks host:dir mountpoint -o reconnect

The client will wait idle for 60 seconds (ServerAliveInterval time) and, send a "no-op null packet" to the server and expect a response. If no response comes, then it will keep trying the above process till 3 (ServerAliveCountMax) times (180 seconds). If the server still doesn't respond, then the client disconnects the ssh connection.

ClientAliveCountMax

ClientAliveCountMax on the server side might also help. This is the limit of how long a client are allowed to stay unresponsive before being disconnected. The default value is 3, as in three ClientAliveInterval.

Config ~/.ssh/config

Host myhostshortcut
     HostName myhost.com
     User barthelemy
     ServerAliveInterval 60
     ServerAliveCountMax 10

Kill the parent process

Kill the parent process, instead of trying to kill the unresponsive process directly.

Find the parent process id ppid of the unresponsive process use

ps -ef

In this case, the parent process of the unresponsive process is the one created by the sshfs command. The following command will help to find it in the list of running processes.

ps -ef | grep sshfs

If you have the ppid, use the kill command with the pid.

kill -9 1268

Kill the parent process should terminate the child process as well.

TVG
  • 143
Z0OM
  • 3,149
  • I got the problem again. It is maybe from a server to which I didn't configure ServerAliveInterval yet. I managed to kill the parent process by looking for the ppid with ps -ef | grep sshfs. I think it could be nice to add it to your answer. It takes me a little time to understand that the "parent" process was the one generated by the sshfs command. I'll make a few more tests with the ServerAliveInterval to see if the problem persists or not. – TVG Jun 12 '23 at 18:34
  • @TVG | One solution is to set up a script or a system service that automatically reconnects the SSHFS mount when the client wakes up from sleep. Use tools like systemd (system service) or creating a custom script that detects the client's sleep/wake events and triggers the reconnection process. – Z0OM Jun 13 '23 at 08:03
  • Create a service | https://linuxhandbook.com/create-systemd-services/ | https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6 – Z0OM Jun 13 '23 at 08:06
  • Thanks. I'm not sure I want to add a system service. Let's see first if ServerAliveInterval solved the problem. – TVG Jun 13 '23 at 11:14