LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2015, 06:26 PM   #1
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Rep: Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162
How to terminate a stale NFS connection


Sometimes an NFS connection does not terminate gracefully. The NFS server will still show an ESTABLISHED connection.

For example, client 192.168.1.7 connects to server 192.168.1.5 to browse some shared files. A power outage occurs and client 192.168.1.7 goes offline. Using netstat, 192.168.1.5 still shows an ESTABLISHED connection.

Or, for some reason the network connection is interrupted but several minutes later when reestablished, netstat will show the new connection and the stale connection as ESTABLISHED.

There are many articles online about using tcpkill and fuser. A challenge is tcpkill succeeds only with active connections. When the remote system is no longer actually connected then tcpkill hangs and does nothing.

Similarly, fuser -k 2049/tcp does nothing as well.

How to forcibly terminate the stale connection?
 
Old 02-13-2015, 07:49 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I think you want to change the default timeouts (which can last about 30 minutes). Normal TCP timeouts are about 15 minutes, so the connection should get cleared then.
 
Old 02-18-2015, 09:13 PM   #3
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Original Poster
Rep: Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162
I wonder whether moving everything to samba might be less stressful. For too many years I have tolerated the way NFS doesn't handle disconnections.
 
Old 02-19-2015, 05:12 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
If you are willing to accept the lower security... and the increased complexity in getting file access.

You can always specify using UDP instead of TCP. TCP is faster, but UDP doesn't have persistent connections.

BTW, those persistent connections always happen with any TCP connection that isn't shutdown. Even sshd connections are persistent, which is one reason they implemented the "keep alive" option - as it polls to see if the remote client is actually there, and then gracefully closes the connection if it doesn't get a reply.

Last edited by jpollard; 02-19-2015 at 05:17 AM.
 
Old 02-19-2015, 09:49 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by jpollard View Post
Even sshd connections are persistent, which is one reason they implemented the "keep alive" option - as it polls to see if the remote client is actually there, and then gracefully closes the connection if it doesn't get a reply.
Is there any reason why NFS hasn't implemented something similar?

Honestly I'm on both sides of the fence here. I've had an NFS connection established, then the server goes down for some reason without cleanly disconnecting first. When that happens, the client just sits there and waits. This can be a pain when you just want a clean disconnect, but it can also be nice...boot the server back up and everything that was waiting just picks back up where it left off like nothing happened.

Even if NFS did implement an auto-disconnect, I'm not sure if I'd even want it. In many instances it's just too convenient to have your processes sit there and wait patiently until the server is back up, rather than having them violently crash because the files/dirs they were reading/writing to have suddenly disappeared, then you have to go through the hassle of restarting them once the server is back up.

Last edited by suicidaleggroll; 02-19-2015 at 09:50 AM.
 
Old 02-19-2015, 10:28 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by suicidaleggroll View Post
Is there any reason why NFS hasn't implemented something similar?
Yes. Most people don't like the data corruption that can occur when a forced disconnect happens.
Quote:
Honestly I'm on both sides of the fence here. I've had an NFS connection established, then the server goes down for some reason without cleanly disconnecting first. When that happens, the client just sits there and waits. This can be a pain when you just want a clean disconnect, but it can also be nice...boot the server back up and everything that was waiting just picks back up where it left off like nothing happened.
That is what the nfs mount option "hard" and "soft" are for. A hard mount is a constant retry, and hangs the client - and is used to avoid data corruption. A "soft" mount allows the client to interrupt an operation, but at the cost of possible data corruption.
Quote:
Even if NFS did implement an auto-disconnect, I'm not sure if I'd even want it. In many instances it's just too convenient to have your processes sit there and wait patiently until the server is back up, rather than having them violently crash because the files/dirs they were reading/writing to have suddenly disappeared, then you have to go through the hassle of restarting them once the server is back up.
Including the possibility of having corrupted files from I/O transactions that haven't completed.
 
Old 02-19-2015, 01:39 PM   #7
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Original Poster
Rep: Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162
Quote:
A "soft" mount allows the client to interrupt an operation, but at the cost of possible data corruption.
How does that work exactly? In my use case I am not running a dedicated 24/7 NFS server. Basically I am using peer sharing. I use a long tested script to connect to other systems in my home network and another script to disconnect. Yet sometimes weird things happen when the scripts are automated and a clean termination does not occur. Seems soft connections might help.

As I am using more of a peer connection than dedicated server, seems the potential of data loss is minimal for my use case. I don't need any kind of automatic disconnect. I need a way to allow manual forced disconnections.

I can test with the soft parameter, but my question is focused on how to force termination? That is, suppose I connect to my HTPC to transfer files, walk away to do something else, and then return, forgetting I had enabled NFS sharing on the HTPC. I shut down the HTPC, but the client is still connected. Then when I attempt to shutdown the client the client hangs. That is where I need the ability to force the shutdown and avoid the hang.

Or does using the soft parameter avoid the whole force termination problem?
 
Old 02-19-2015, 02:08 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by upnort View Post
That is, suppose I connect to my HTPC to transfer files, walk away to do something else, and then return, forgetting I had enabled NFS sharing on the HTPC. I shut down the HTPC, but the client is still connected. Then when I attempt to shutdown the client the client hangs. That is where I need the ability to force the shutdown and avoid the hang.
Use "umount -fl" to force the client to unmount the share.
 
Old 02-19-2015, 03:50 PM   #9
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Original Poster
Rep: Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162
Quote:
Use "umount -fl" to force the client to unmount the share.
I already do that and have done so for years. Often fails to work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Stale NFS handle on embedded system that does not have NFS running CollieJim Linux - Embedded & Single-board computer 6 03-29-2012 07:50 AM
xfs, inode64, NFS export, no_subtree_check and "Stale NFS file handle" message mcacciagrano Red Hat 1 01-16-2011 03:25 PM
"Stale NFS file handle" mount error on a non-NFS /boot partition after running lilo cabrilo Slackware 4 09-14-2010 09:00 AM
NFS stale file handle and not using NFS odjb Linux - Newbie 3 11-05-2009 09:41 AM
ls: cannot access /etc/resolv.conf: stale nfs file handle - but i'm not using nfs schneidz Linux - General 4 10-02-2009 02:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration