Bug in CFS with large files download

This bug appeared to us since our product can deal with really big files inside Community Server. So where it happens? It happens when you have big files, something like 100+ Mb and when you store them on the network storage.

See technical details and fix for this issue below. 

It's all about Response buffer. Telligent use custom code to download from network storage (for files located on CS instance itself they use Response.TransmitFile() and it work just fine).

FileSystemFileStorageProvider.cs

using (Stream s = new FileStream(file.FullLocalPath, FileMode.Open, FileAccess.Read))
{
  byte[] buffer = new byte[64 * 1024];
  int read;
  while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
  {
    if (!context.Response.IsClientConnected)
      break;
    context.Response.OutputStream.Write(buffer, 0, read);
  }
  context.Response.OutputStream.Flush();
  context.Response.Flush();
  context.Response.Close();
  s.Close();
}


 How to resolve:

1. Replace code mentioned above in source file (SDK version) and rebuild. 

using (Stream s = new FileStream(file.FullLocalPath, FileMode.Open, FileAccess.Read))
{
  context.Response.Buffer = false;
  context.Response.BufferOutput = false;
  try
  {

    byte[] buffer = new byte[64 * 1024];
    int read;
    while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
    {
      if (!context.Response.IsClientConnected) break;
      context.Response.OutputStream.Write(buffer, 0, read);
      context.Response.OutputStream.Flush();
    }
  }
  catch (HttpException) { }
  catch (Exception ex)
  {
    new CSException(CSExceptionType.UnknownError, "FileSystemFileStorageFile", ex).Log();
  }

  context.Response.Flush();
  context.Response.Close();
  s.Close();
}


 2. Now we need to create our own HttpHandler from FileSystemFileStorageHttpHandler class and change web.config httpHandlers section, so CS work with our handler rather than default from Telligent.

web.config (original)
<add verb="GET" path="cfs-filesystemfile.ashx" type="CommunityServer.Components.FileSystemFileStorageHttpHandler, CommunityServer.Components" />
to
<add verb="GET" path="cfs-filesystemfile.ashx" type="Upupo.Media.FileSystemFileStorageHttpHandler, Upupo.Media" />


 3. Completely remove (or comment) line

<add verb="GET" path="cfs-filesystemfile.ashx" type="CommunityServer.Components.FileSystemFileStorageHttpHandler, CommunityServer.Components" />

 


in web.config and copy file cfs-filesystemfile.ashx (attached) to root of web site.

Have a nice hacking!

By the way, this bug already fixed on our products 

 

 


Posted Feb 03 2009, 06:16 PM by x893
Filed under: ,