0

I have an action method in my MVC app which returns a FileResult based on a file saved as a blob in the database. The root problem is that for some file types, requesting the file returns an empty file, even though I've verified that the database has the correct contents encoded in the Content column.

However, the really odd part is how difficult it is to me to pin down exactly what's causing this. Here's a few gotchas that I can't make sense of:

  • Downloading text files, like *.txt and *.csv returns an empty file, while downloading e.g. a PDF works correctly

  • This only happens on our CI server, and I can't reproduce it on my local workstation. These are the only differences I can think of:

    • I've verified that a commit that works on my machine, doesn't work on the CI server
    • I've tried connecting the local workstation to the CI server's database engine, and was not able to reproduce. In other words, the problem is in the code, rather than in the database (but as pointed out, the same code that works locally doesn't work on the CI server...).
    • The CI server runs IIS7, while I test locally on IIS Express that ships with Visual Studio

How do I trouble-shoot this? What could cause it?

Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • Have you tried to log information about how it going? Can you share your code? I think it is not enough to answer now... – Sergey Malyutin Oct 17 '14 at 13:15
  • Nobody can answer this. There is no answer like _"FileResult in CI is known to return empty files for text/* content type"_. Add logging, use Fiddler to inspect the HTTP request and its response. Eliminate all irrelevant code. Does a FileResult from a string instead of from the database show the same behavior? How do you download the file? How do you determine it is empty? What CI server? And so on. – CodeCaster Oct 17 '14 at 13:23
  • My main question here is **how do I troubleshoot this?** I've deliberately not tried to include a code sample in the question, since I cannot reproduce it locally (and therefore have a very difficult time narrowing it down to what parts of the code are relevant; including the complete source is not an option). Since the feedback loop to make changes on the CI server is very long (from a push to Github it takes ~10 minutes before I can test the changes) I was hoping to gather some tips on how to troubleshoot without having to "make a small change/recomile/see what happened" for each attempt. – Tomas Aschan Oct 17 '14 at 13:37
  • I also don't know enough about possible causes for something like this to have much use of tools like Fiddler - I have no clue what I'm looking for. – Tomas Aschan Oct 17 '14 at 13:40

1 Answers1

0

OK, as expected from how the question is written, this problem was highly specific to our setup, so the actual fix for me is probably not that interesting. However, in order to (hopefully) be helpful to someone else stumbling over similar problems and finding their way here (welcome!), I'll post a summary of the troubleshooting campaign that eventually helped me find the root cause and fix it.

tl;dr: The problem in this case was custom HTTP compression - when turned off, everything worked.

Troubleshooting this type of problems - hints that would have helped me to resolve this faster:

  1. Are you sure that your local settings reflect those of the production/staging environment? Not just that they're supposed to, but that they actually do - if you're having problems reproducing the error, then it's almost certainly due to something here.

    Some things that could vary:

    • Build configurations: Debug/Release/OtherConf setting in build scripts? In IDE?
    • Web.config: we have a local Web.config file that is used by devs, but create the production version in our build script based on a template Web.config.erb. Do all versions match?
    • IIS settings: Do you have some custom settings in IIS on the production/staging server that handle serving of non-text/html data (or whatever it is that is failing)? Do you use the same settings locally?
       

    Still haven't found anything? Well, there are other ways to look for differences than manually.

  2. Try to side-step the CI build process, and publish your local (working) version of the app to the server. Hopefully, it can reveal some discrepancy that you missed.

  3. If you still cannot find a setting that differs, and still cannot reproduce it locally, can you debug on the server? If you don't have VS installed on the server, maybe give Remote debugging a try. (I didn't manage to get it working before I found the problem, mainly because it was excruciatingly slow on our setup, but it's well worth a try...)

Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402