File Locking problem when Dispose throws exception

File Locking problem when Dispose throws exception

am 30.10.2007 21:33:29 von jeevankodali

Hi

I have a multi threaded ftp server. 2 days back it threw an exception:
System.IO.IOException: The specified network name is no longer
available.

at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset,
Int32 count)
at System.IO.FileStream.FlushWrite()
at System.IO.FileStream.Flush()
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Close()
at System.IO.Stream.System.IDisposable.Dispose()

That happened because there was some problem with out file server. But
as you can see, it happened in Dispose function of FileStream. This
caused the lock on the file to be left as it is. We were able to
manually delete/rename the file from other machines but this process
was not able to access this file again throwing "it is being used by
another process." on future tries.

Restarting the file server did not help but restarting the ftp server
process fixed this problem. But I am trying to see if there is any way
this problem can be handled automatically. Usually it is said that
"using" block takes care of unexpected crashes but what if something
like this fails inside the Dispose, how can we remove the handle?

Thanks
Jeevan