jordanlytle / SmbAbstraction

Implements the System.IO.Abstractions interfaces for interacting with the filesystem, and adds support for interacting with UNC or SMB paths
MIT License
6 stars 8 forks source link

SMBDirectory.Exists is very slow - STATUS_INVALID_SMB error #39

Open kechf opened 4 years ago

kechf commented 4 years ago

Hi, when I try to use Directory.Exists by using SMBDirectory, the fileStore.CloseFile(fileHandle); function is very slow (over 10 sec.).

The reason could be, that I'm getting an SMB error STATUS_INVALID_SMB during closing the file handle.

Here is an example where the problem occurs...

// Bootstrap mit credentials caching...
credentialProvider.AddSMBCredential(new SMBCredential(credential.Domain, credential.UserName, credential.Password, @"\\host\myshare", credentialProvider));
BindInstance<IFileSystem>(new SMBFileSystem(smbClientFactory, credentialProvider, 65536u));

// usage
 var exists = _fileSystem.Directory.Exists(fileRootPath);
 if (!exists)
 {
   _fileSystem.Directory.CreateDirectory(fileRootPath);
 }

What goes wrong here?

nareshn2003 commented 3 years ago

Hi

I am having same problem . You able to solve this issue ?

nareshn2003 commented 3 years ago

To update, This might help someone .

I solved the problem using adding FileStoreUtilities.CloseFile(fileStore, ref handle); in SMBDirectory.cs at before line number 737.

FileStoreUtilities.CloseFile(fileStore, ref handle); in finally block cause slow operation not sure why.