sshfs icon indicating copy to clipboard operation
sshfs copied to clipboard

Properly unmount on Ctrl-C

Open iFreilicht opened this issue 7 years ago • 9 comments

In my local network, I am running the following command (user and remote name anonymised):

sshfs myself@remote:/home.net/myself ~/remote
myself@remote's password:
<CTRL+C>

When using CTRL+C while entering the password, the directory will be mounted with an unconnected endpoint, so it's there but not usable:

mount -l
[...]
myself@remote:/home.net/myself on /home/myself/remote type fuse.sshfs (rw,nosuid,nodev,user=myself)
ls ~/remote
ls: transport endpoint is not connected: /home/myself/remote

This means that re-trying to mount it will fail:

sshfs myself@remote:/home.net/myself ~/remote
fuse: bad mount point `/home/myself/remote': Transport endpoint is not connected

The workaround is to manually unmount it and then try again:

fusermount -u remote
sshfs myself@remote:/home.net/myself ~/remote
myself@remote's password:

However, it would be nice if sshfs failed gracefully and automatically unmounted the non-connected directory for me.

iFreilicht avatar Dec 28 '17 10:12 iFreilicht

Thanks for the report, and sorry for not responding for so long. I agree that it would be nice to handle better. Unfortunately I probably won't have time to work on this anytime soon, but I'll keep the bug open.

Nikratio avatar Jun 22 '18 09:06 Nikratio

Was this fixed? I was not able to reproduce this issue:

root@beer:/mnt# sshfs root@localhost:/root /mnt/sshfs
root@localhost's password: 
read: Interrupted system call
root@beer:/mnt# mount -l | grep sshfs
root@beer:/mnt# 

yanir3 avatar Feb 21 '19 15:02 yanir3

I'm not aware of any deliberate changes. It may have been a side effect of something else...

Nikratio avatar Feb 25 '19 21:02 Nikratio

Looking at libfuse source code, it seems libfuse handles SIGINT specially and does a graceful exit with umount.

Another advice is to use option -o auto_unmount if you want the fusermount helper to unmount the filesystem when the sshfs process is hard killed. I use that flag in unit tests to not leave dangling stale mounts behind.

I think this issue can be closed.

kalvdans avatar Oct 19 '19 20:10 kalvdans

I don't think libfuse is able to deal with the SSH process being Ctrl-C'ed, this will need treatment in sshfs.

Nikratio avatar Oct 19 '19 21:10 Nikratio

You are right. Sorry for the noise, I didn't read the description properly.

kalvdans avatar Oct 19 '19 21:10 kalvdans

@Nikratio if you can point me to where the ssh/sftp (on macOS "ssh" is the process listed) is called, I'll provide the fix to handle when the SSH process quits on a SIGINT.

keithmendozasr avatar Nov 30 '19 02:11 keithmendozasr

@keithmendozasr I did some code excavation and it looks like connect_remote is always called on startup. I think start_ssh is called the first time, although there's a branch in connect_remote so I'm not sure.

jyn514 avatar Dec 17 '19 03:12 jyn514