title: nginx - fastcgi-mono-server 4 : upstream prematurely closed connection while reading response header from upstream
body: <p>I am using fast-cgi-mono-server for a local asp.net web application on my macbook pro.</p>
  
  <p>Configurations are:
  - nginx 1.6.2
  - php 5.5.14
  - php-fpm 5.5.14
  - mono 3.12.0</p>
  
  <p>In general, all works fine, up to one page. When loading the page, the server crashes and I really struggle to understand why.</p>
  
  <p>To be as precise as possible, here are the configuration files along with the different logs I think are meaningful:</p>
  
  <ol>
  <li><p>nginx.conf:    </p>
  
  <pre><code>worker_processes  1;
  </code></pre>
  
  <p>events {
              worker_connections  758;
     }</p>
  
  <p>http {
      include        mime.types;
      default_type   application/octet-stream;
      access_log     /var/www/log/nginx.access.log;
      error_log      /var/www/log/nginx.error.log;</p>
  
  <pre><code># Basic Settings
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  
  
  include /usr/local/etc/nginx/sites-enabled/*;
  </code></pre>
  
  <p>}</p></li>
  <li><p>Unique enabled site (<code>/usr/local/etc/nginx/sites-enabled/mysite</code>)</p>
  
  <p>`server {
          listen  80;
          server_name     my.site.com;
          access_log      /var/www/log/my.site.com.access.log;
          error_log       /var/www/log/my.site.com.error.log;</p>
  
  <pre><code>    client_header_timeout 2000;
      client_body_timeout 2000;
      send_timeout 2000;
  
      location / {
              root /var/www/myApp;
              index index.aspx index.html index.htm default.aspx Default.aspx;
              fastcgi_index Default.aspx;
              fastcgi_pass 127.0.0.1:9000;
  
              #fastcgi_pass unix:/var/run/php5-fpm.sock;
              include /usr/local/etc/nginx/fastcgi_params;
      }
  </code></pre>
  
  <p>}</p></li>
  <li><p><code>my.site.com.error.log</code></p></li>
  </ol>
  
  <p>2015/02/09 10:10:22 [error] 1239#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: my.site.com, request: "GET /Views/RecipeReportViewer.aspx HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1", referrer: "<a href="http://127.0.0.1/" rel="nofollow">http://127.0.0.1/</a>"</p>
  
  <ol start="4">
  <li><p>mono-error crash</p>
  
  <p>[2015-02-09 10:20:00Z] Notice  Beginning to receive records on connection.</p>
  
  <p>Feb  9 10:20:01 macbook.local mono[1301] : CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.</p>
  
  <p>Feb  9 10:20:01 macbook.local mono[1301] : CGContextSynchronize: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.</p>
  
  <p>Feb  9 10:20:01 macbook.local mono[1301] : CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.</p>
  
  <p>Trace/BPT trap: 5</p></li>
  </ol>
  
  <p>I have tried increasing buffers and timeout times for both fastcgi and nginx, but crash occurs nearly immediately on load si I doubt timeout is the issue here... I also isolated my line of code that is crashing the code (and which works perfectly fine on Debian, same configuration except I use Mono 3.10)...</p>
  
  <p>If any useful, the line crashing is when calling a DevExpress library, namely the ASPXDocumentViewer. What fails is</p>
  
  <pre><code>this.ASPxDocumentViewer1.Report = rep;
  </code></pre>
  
  <p>I.e. when I programmatically set the report instance. Again, this works fine on Debian.</p>
  
  <p>Is downgrading Mono my only option, or am I missing something obvious here that makes the library to crash ?</p>
  
  <p>Thanks in advance!
  Regards,
  N.</p>
  
  <p>EDIT: I just upgraded to Mono 3.12 on Debian and it works fine. So it's not about mono version. Any idea on where to look? Thanks!</p>