Search code examples
c#androidlinuxmononancy

NancyFX/Linux/Mono - Large uploads (over 1MB) work on windows server but not linux


I seem to have a rather strange problem which I was wondering if anyone could shed a light on.

I am writing an Android app which uploads/downloads files from a self hosted C# server. The server is written in C# (using NancyFX self-host) and the Android app is using HttpClient (Apache) to talk to the server.

When I attempt to upload the files on windows (which is where I manually debug into the server code), the upload works fine for any number of files with any arbitrary length. Everything works as expected and both small and large files get uploaded.

However, when I deploy this server to my Linux box (OpenSuSe) and run it, the uploads behave differently. The smaller files (< 1MB) still work as expected but when the file goes over this limit, the HttpClient's .execute() hangs indefinitely. I tried to set the socket timeout to 10 seconds (to test) and I once received a socket timeout exception but other times, it simply hung there, never even timing out. It's also worth mentioning that the request never reaches the server which would implicate that the problem is most probably not with the Nancy server (although I could be wrong).

Given the nature of the problem, I'm inclined to believe that the problem lies somewhere in the Linux server configuration which does not allow larger POST requests for whatever reason but I've not been able to figure out why that would be the case. I do have a PHP server on that very same Linux box and on that, I can upload files larger than 1MB without any problems.

Other steps I've tried: I've disabled the firewall on the Linux server to see if it was a firewall problem (highly unlikely since <1MB reaches the server just fine) but that didn't help. I also changed the MTU to be in-line with my windows machine but that did not make a difference either.

As it stands, I'm out of ideas. Does anyone know how to trace this further to get to the bottom of the problem? Any help would be greatly appreciated.

Many thanks in advance.


Solution

  • I've fixed the problem with the hanging after spending a lot of time googling it. The problem was with Mono and has been fixed in the latest version (3.4). I've installed this version on my Linux box and the hanging issue is gone.

    More details here: https://github.com/mono/mono/commit/a31b580fdcbaa9a8a16d59ffb12d04f5872f54e8

    I have another problem now though. The image file that is retrieved on the server side is corrupt. Given the fact that the very same code works in Windows, I'm inclined to believe the issue rests with Mono or more likely, with NancyFx's code on Mono. I will debug further into it and update the progress of this question, in case anyone else ever runs into the same issue.