0

I have a Web API that is responsible for saving files to a network path (NFS), Every 50-60 calls i'm getting "Network path was not found", when even trying to validate the location:

Directory.CreateDirectory(path);

and also when trying to write files.

usually 2-3 tracking requests will receive this error and then it returns to normal.

Where path is a network location \\10.169.10.148\storage\

The location exists, and it's not a permission issue since I do manage to write to this location for most of the calls.

The error occurs on multiple endpoints, each trying to save files in a different way.

One is receiving a url and trying to download a remote file to the disk

using (WebClient webClient = new WebClient())
{
    await webClient.DownloadFileTaskAsync(new Uri(video.FullPath), fullFilePath);
}

One is receiving the file itself:

using (Bitmap bmp1 = new Bitmap(fileContent.ReadAsStreamAsync().Result))
{
    Directory.CreateDirectory(path);
    ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);

    System.Drawing.Imaging.Encoder myEncoder =
    System.Drawing.Imaging.Encoder.Quality;

    EncoderParameters myEncoderParameters = new EncoderParameters(1);

    EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
    myEncoderParameters.Param[0] = myEncoderParameter;

    bmp1.Save(filePath, jpgEncoder, myEncoderParameters);
}

And one is receiving a JSON string and writing it to a file:

public IHttpActionResult Post([FromBody] CreationJSON settings)
{
    var location = Path.Combine(path, fileName);
    File.WriteAllText(location, settings.JSON);

    return Created(new Uri(location), fileName);
}

All try/catch and logging code was removed for clarity.

I receive around 20k requests per day, not a heavy load, and the error can occur after a few minutes of having no requests.

This Web API is written in C#, .NET 4.6 running on IIS 8.5 on a Windows Server 2012 R2 machine.

I'm aware of this similar question: C# The network path was not found

but it wasn't resolved.

Any help would be much appreciated.

Ariel Haim
  • 86
  • 7
  • Im confused how those 3 portions hang together, if you've got a NFS (windows and NFS dont always play nice) where is the webclient bit involved – BugFinder Mar 26 '18 at 07:14
  • These are 3 different endpoints on the same controller. The webclient downloads a remote mp4 file and saves it to the \\10.0.0.0 path – Ariel Haim Mar 26 '18 at 07:56
  • Is there any chance that the fails come after a bigger delay from the last call? are there any errors showing on the NFS server? – BugFinder Mar 26 '18 at 08:39
  • Actually I'm less familiar with this server, it's under our DevOps responsibility, any specific logs or errors I should look for? – Ariel Haim Mar 26 '18 at 10:47
  • timeouts, login errors, anything from the machine in question to be fair – BugFinder Mar 26 '18 at 11:10

0 Answers0