# Sendfile EAGAIN and FastCGI

**URL:** <https://www.ruby-forum.com/t/sendfile-eagain-and-fastcgi/208393>\
**Category:** NGINX\
**Created:** [June 17, 2011, 12:27am UTC](https://www.ruby-forum.com/t/sendfile-eagain-and-fastcgi/208393 "2011-06-17T00:27:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 17, 2011, 12:27am UTC](https://www.ruby-forum.com/t/sendfile-eagain-and-fastcgi/208393/1 "2011-06-17T00:27:11Z")

</div>

Hello. I’m using FreeBSD 7.4-RELEASE with Nginx 1.0.3 built from ports:

# nginx -V

nginx: nginx version: nginx/1.0.3  
nginx: TLS SNI support enabled  
nginx: configure arguments: --prefix=/usr/local/etc/nginx  
–with-cc-opt=‘-I /usr/local/include’ --with-ld-opt=‘-L /usr/local/lib’  
–conf-path=/usr/local/etc/nginx/nginx.conf  
–sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid  
–error-log-path=/var/log/nginx-error.log --user=www --group=www  
–with-debug --with-file-aio  
–http-client-body-temp-path=/var/tmp/nginx/client\_body\_temp  
–http-fastcgi-temp-path=/var/tmp/nginx/fastcgi\_temp  
–http-proxy-temp-path=/var/tmp/nginx/proxy\_temp  
–http-scgi-temp-path=/var/tmp/nginx/scgi\_temp  
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\_temp  
–http-log-path=/var/log/nginx-access.log  
–with-http\_gzip\_static\_module  
–with-http\_realip\_module --with-http\_ssl\_module  
–with-http\_stub\_status\_module --with-http\_sub\_module --with-pcre

I’m also using FCGI to run a web application:

# pkg\_info | grep FCGI

p5-FCGI-ProcManager-0.19 Functions for managing FastCGI applications  
p5-FCGI-Spawn-0.16.1 FastCGI server for CGI-like applications  
multiprocessing

It appears when I make a request larger than some value, the debug  
output claims that sendfile() is returning EAGAIN, at which point the  
request times out. Is this my misconfiguration, an nginx bug, an OS bug,  
or something else I’ve not yet figured out? Debug output follows:

2011/06/16 12:54:07 [debug] 51363#0: \*1 http cl:21413 max:115343360  
2011/06/16 12:54:07 [debug] 51363#0: \*1 rewrite phase: 3  
2011/06/16 12:54:07 [debug] 51363#0: \*1 post rewrite phase: 4  
2011/06/16 12:54:07 [debug] 51363#0: \*1 generic phase: 5  
2011/06/16 12:54:07 [debug] 51363#0: \*1 generic phase: 6  
2011/06/16 12:54:07 [debug] 51363#0: \*1 generic phase: 7  
2011/06/16 12:54:07 [debug] 51363#0: \*1 access phase: 8  
2011/06/16 12:54:07 [debug] 51363#0: \*1 access phase: 9  
2011/06/16 12:54:07 [debug] 51363#0: \*1 post access phase: 10  
2011/06/16 12:54:07 [debug] 51363#0: \*1 try files phase: 11  
2011/06/16 12:54:07 [debug] 51363#0: \*1 posix\_memalign:  
0000000801268000:4096 @16  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http client request body  
preread  
8118  
2011/06/16 12:54:07 [debug] 51363#0: \*1 malloc: 0000000801269000:8192  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http read client request body  
2011/06/16 12:54:07 [debug] 51363#0: \*1 SSL\_read: 7177  
2011/06/16 12:54:07 [debug] 51363#0: \*1 SSL\_read: 1015  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http client request body recv  
8192  
2011/06/16 12:54:07 [debug] 51363#0: \*1 add cleanup: 0000000801268248  
2011/06/16 12:54:07 [debug] 51363#0: \*1 hashed path:  
/var/tmp/nginx/client\_body\_temp/0000000001  
2011/06/16 12:54:07 [debug] 51363#0: \*1 temp fd:34  
2011/06/16 12:54:07 [warn] 51363#0: \*1 a client request body is  
buffered to  
a temporary file /var/tmp/nginx/client\_body\_temp/0000000001, client:  
205.147.26.121, server: [wiki.dream-tech.com](http://wiki.dream-tech.com), request: “POST  
/bin/save/Some/File HTTP/1.1”, host: “[wiki.dream-tech.com](http://wiki.dream-tech.com)”, referrer:  
“[https://mywiki.dream-tech.com/bin/edit/Some/File?t=1308252237;nowysiwyg=1](https://mywiki.dream-tech.com/bin/edit/Some/File?t=1308252237;nowysiwyg=1)”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 write: 34, 0000000801269000,  
8192, 0  
2011/06/16 12:54:07 [debug] 51363#0: \*1 SSL\_read: 5103  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http client request body recv  
5103  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http client request body rest  
0  
2011/06/16 12:54:07 [debug] 51363#0: \*1 write: 34, 0000000801269000,  
5103,  
8192  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http init upstream, client  
timer: 0  
2011/06/16 12:54:07 [debug] 51363#0: \*1 kevent set event: 33: ft:-2  
fl:0025  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“LOCATION\_MATCH”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy: “bin”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“LOCATION\_MATCH: bin”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SCRIPT\_FILENAME”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“/www/foswiki”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “/bin/save”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“SCRIPT\_FILENAME:  
/www/foswiki/bin/save”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy: “PATH\_INFO”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “/Some/File”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “PATH\_INFO:  
/Some/File”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SCRIPT\_NAME”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “/bin/save”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “SCRIPT\_NAME:  
/bin/save”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“QUERY\_STRING”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “QUERY\_STRING:  
"  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“REQUEST\_METHOD”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “POST”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“REQUEST\_METHOD:  
POST”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“CONTENT\_TYPE”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“application/x-www-form-urlencoded”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “CONTENT\_TYPE:  
application/x-www-form-urlencoded”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“CONTENT\_LENGTH”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “21413”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“CONTENT\_LENGTH:  
21413”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SCRIPT\_NAME”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “/bin/save”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “SCRIPT\_NAME:  
/bin/save”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“REQUEST\_URI”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“/bin/save/Some/File”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “REQUEST\_URI:  
/bin/save/Some/File”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“DOCUMENT\_URI”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“/bin/save/Some/File”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “DOCUMENT\_URI:  
/bin/save/Some/File”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“DOCUMENT\_ROOT”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“/www/mywikis/mywiki.dream-tech.com”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“DOCUMENT\_ROOT:  
/www/mywikis/mywiki.dream-tech.com”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SERVER\_PROTOCOL”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “HTTP/1.1”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“SERVER\_PROTOCOL:  
HTTP/1.1”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“GATEWAY\_INTERFACE”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy: “CGI/1.1”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“GATEWAY\_INTERFACE:  
CGI/1.1”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SERVER\_SOFTWARE”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy: “nginx/”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “1.0.3”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“SERVER\_SOFTWARE:  
nginx/1.0.3”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“REMOTE\_ADDR”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“205.147.26.121”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “REMOTE\_ADDR:  
205.147.26.121”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“REMOTE\_PORT”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “52063”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “REMOTE\_PORT:  
52063”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SERVER\_ADDR”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“205.147.26.122”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “SERVER\_ADDR:  
205.147.26.122”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SERVER\_PORT”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var: “443”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “SERVER\_PORT:  
443”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“SERVER\_NAME”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script var:  
“[wiki.dream-tech.com](http://wiki.dream-tech.com)”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “SERVER\_NAME:  
[wiki.dream-tech.com](http://wiki.dream-tech.com)”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy:  
“REDIRECT\_STATUS”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http script copy: “200”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“REDIRECT\_STATUS:  
200”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “HTTP\_HOST:  
[wiki.dream-tech.com](http://wiki.dream-tech.com)”  
2011/06/16 12:54:07 [debug] 51363#0: _1 fastcgi param:  
“HTTP\_USER\_AGENT:  
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.0.1) Gecko/20100101  
Firefox/4.0.1”  
2011/06/16 12:54:07 [debug] 51363#0: 1 fastcgi param: "HTTP\_ACCEPT:  
text/html,application/xhtml+xml,application/xml;q=0.9,/_;q=0.8”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“HTTP\_ACCEPT\_LANGUAGE: en-us,en;q=0.5”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“HTTP\_ACCEPT\_ENCODING: gzip, deflate”  
2011/06/16 12:54:07 [debug] 51363#0: _1 fastcgi param:  
"HTTP\_ACCEPT\_CHARSET: ISO-8859-1,utf-8;q=0.7,_;q=0.7"  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“HTTP\_KEEP\_ALIVE:  
115”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “HTTP\_DNT: 1”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“HTTP\_CONNECTION:  
keep-alive”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param: “HTTP\_REFERER:  
[https://mywiki.dream-tech.com/bin/edit/Some/File?t=1308252237;nowysiwyg=1](https://mywiki.dream-tech.com/bin/edit/Some/File?t=1308252237;nowysiwyg=1)”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“HTTP\_CONTENT\_TYPE:  
application/x-www-form-urlencoded”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 fastcgi param:  
“HTTP\_CONTENT\_LENGTH: 21413”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http cleanup add:  
0000000801268BF8  
2011/06/16 12:54:07 [debug] 51363#0: \*1 get rr peer, try: 1  
2011/06/16 12:54:07 [debug] 51363#0: \*1 socket 35  
2011/06/16 12:54:07 [debug] 51363#0: \*1 connect to  
unix:/var/tmp/sockets/foswiki, fd:35 #2  
2011/06/16 12:54:07 [debug] 51363#0: \*1 kevent set event: 35: ft:-1  
fl:0025  
2011/06/16 12:54:07 [debug] 51363#0: \*1 connected  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http upstream connect: 0  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http upstream send request  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer buf fl:0 s:1720  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer buf fl:0 s:8118  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer buf fl:0 s:10  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer buf fl:0 s:13295  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer buf fl:0 s:9  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer in:  
0000000801268C90  
2011/06/16 12:54:07 [debug] 51363#0: \*1 sendfile() sent only 9848  
bytes  
(35: Resource temporarily unavailable)  
2011/06/16 12:54:07 [debug] 51363#0: \*1 sendfile: -1, @0 9848:13295  
2011/06/16 12:54:07 [debug] 51363#0: \*1 chain writer out:  
0000000801268CC0  
2011/06/16 12:54:07 [debug] 51363#0: \*1 event timer add: 35:  
60000:1308254107181  
2011/06/16 12:54:07 [debug] 51363#0: \*1 kevent set event: 35: ft:-2  
fl:0025  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http finalize request: -4,  
“/bin/save/Some/File?” a:1, c:2  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http request count:2 blk:0  
2011/06/16 12:54:07 [debug] 51363#0: \*1 post event 00000008012DE150  
2011/06/16 12:54:07 [debug] 51363#0: \*1 delete posted event  
00000008012DE150  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http run request:  
“/bin/save/Some/File?”  
2011/06/16 12:54:07 [debug] 51363#0: \*1 http upstream check client,  
write  
event:1, “/bin/save/Some/File”  
2011/06/16 12:55:07 [debug] 51363#0: \*1 event timer del: 35:  
1308254107181  
2011/06/16 12:55:07 [debug] 51363#0: \*1 http upstream request:  
“/bin/save/Some/File?”  
2011/06/16 12:55:07 [debug] 51363#0: \*1 http upstream send request  
handler  
2011/06/16 12:55:07 [debug] 51363#0: \*1 http next upstream, 4  
2011/06/16 12:55:07 [debug] 51363#0: \*1 free rr peer 1 4  
2011/06/16 12:55:07 [error] 51363#0: \*1 upstream timed out (60:  
Operation  
timed out) while sending request to upstream, client: 205.147.26.121,  
server:  
[wiki.dream-tech.com](http://wiki.dream-tech.com), request: “POST /bin/save/Some/File HTTP/1.1”,  
upstream:  
“fastcgi://unix:/var/tmp/sockets/foswiki:”, host: “[wiki.dream-tech.com](http://wiki.dream-tech.com)”,  
referrer:  
“[https://mywiki.dream-tech.com/bin/edit/Some/File?t=1308252237;nowysi](https://mywiki.dream-tech.com/bin/edit/Some/File?t=1308252237;nowysi)  
wyg=1”

## Thanks in advance for any insight that can be provided. 🙂

Dave H. - Consultant - Altadena CA, USA - removed\_email\_address@domain.invalid

> > > The opinions expressed above are entirely my own \<\<\<

Do what you can, with what you have, where you are.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 17, 2011, 9:54am UTC](https://www.ruby-forum.com/t/sendfile-eagain-and-fastcgi/208393/2 "2011-06-17T09:54:28Z")

</div>

Hello!

On Thu, Jun 16, 2011 at 03:26:24PM -0700, Dave H. wrote:

> Hello. I’m using FreeBSD 7.4-RELEASE with Nginx 1.0.3 built from ports:

[…]

> It appears when I make a request larger than some value, the debug  
> output claims that sendfile() is returning EAGAIN, at which point the  
> request times out. Is this my misconfiguration, an nginx bug, an OS bug,  
> or something else I’ve not yet figured out? Debug output follows:

This is believed to be sendfile() and unix sockets problem in the  
OS.

Maxim D.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 17, 2011, 8:41pm UTC](https://www.ruby-forum.com/t/sendfile-eagain-and-fastcgi/208393/3 "2011-06-17T20:41:42Z")

</div>

Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> As Maxim already said there is a bug in sendfile/unix socket/FreeBSD  
> combination. You can just disable sendfile in FCGI location:  
> location … {  
> sendfile off;  
> fastcgi\_pass unix:/…  
> …  
> }

Thank you very much, this fixed the issue.

## Out of curiosity, would nginx perform better using “aio” here, if I can’t use sendfile yet?

Dave H. - Consultant - Altadena CA, USA - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > > The opinions expressed above are entirely my own \<\<\<

By definition, when you are investigating the unknown,  
you do not know what you will find or even when you have  
found it.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 17, 2011, 11:22am UTC](https://www.ruby-forum.com/t/sendfile-eagain-and-fastcgi/208393/4 "2011-06-17T11:22:54Z")

</div>

On Thu, Jun 16, 2011 at 03:26:24PM -0700, Dave H. wrote:

> –with-debug --with-file-aio
> 
> # pkg\_info | grep FCGI
> 
> p5-FCGI-ProcManager-0.19 Functions for managing FastCGI applications  
> p5-FCGI-Spawn-0.16.1 FastCGI server for CGI-like applications multiprocessing
> 
> It appears when I make a request larger than some value, the debug  
> output claims that sendfile() is returning EAGAIN, at which point the  
> request times out. Is this my misconfiguration, an nginx bug, an OS bug,  
> or something else I’ve not yet figured out? Debug output follows:

As Maxim already said there is a bug in sendfile/unix socket/FreeBSD  
combination. You can just disable sendfile in FCGI location:

```
location ... {
    sendfile off;
    fastcgi_pass unix:/...
    ...
}

```

–  
Igor S.
