Bug #2263

nginx loses/garbles data if buffering to disk

Added by matthiasr almost 3 years ago. Updated 2 months ago.

Status:ResolvedStart date:12/17/2011
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

I recently moved my web server to DragonFly and noticed that for very large responses from a web app accessed through nginx via fastcgi_pass or proxy_pass parts of the response are lost. This happens in the middle of the response, at more or less random locations (more towards the end). It used to work fine on Debian Linux.

I suspect that this is related to nginx buffering large responses to disk. I have created a testcase (test file, although anything large enough would work; nginx config snippet, repeated test download script, see attachments). With proxy_buffers left at the default, the downloaded file2.txt differs every few attempts. With the buffer size cranked up it works reliably. Both variants work reliably on OS X.

Note that this is also almost a Heisenbug – it takes a lot more tries until something goes wrong while ktrace'ing. ktrace available at http://2pktfkt.de/dfly/nginx_ktrace.out (~300MB – also http://2pktfkt.de/dfly/nginx_ktrace.out.xz soon)

file1.txt Magnifier - test file (586 KB) matthiasr, 12/17/2011 10:52 AM

localhost.conf - nginx snipped (293 Bytes) matthiasr, 12/17/2011 10:52 AM

test.sh Magnifier - repeated test download script (188 Bytes) matthiasr, 12/17/2011 10:52 AM

ktrace.out.xz - sudo ktrace -idp <nginx master process>; ./test.sh; sudo ktrace -c <nginx master process> (640 KB) matthiasr, 12/17/2011 10:55 AM

History

#1 Updated by matthiasr almost 3 years ago

compressed ktrace attached.

#2 Updated by matthiasr almost 3 years ago

It very much seems sendfile is the culprit – after setting 'sendfile off;' in the nginx config I could let the test run for >1h straight without problems.

#3 Updated by jorisgio 2 months ago

  • Description updated (diff)
  • Status changed from New to Resolved

Fixed in 799312a2b6e22a583d98633ea6b62146afa8eb45

Also available in: Atom PDF