Project

General

Profile

Actions

Bug #2329

closed

connection was dropped after accept()

Added by rr over 12 years ago. Updated almost 8 years ago.

Status:
Missing Feedback
Priority:
Normal
Category:
mod_fastcgi
Target version:
-
ASK QUESTIONS IN Forums:

Description

Using mod_fastcgi (1.4.28) with php-fpm (5.3.5) over TCP to localhost on FreeBSD 8. Some percentage of the requests fail with this error:

2011-07-21 13:57:32: (mod_fastcgi.c.3094) connection was dropped after accept() (perhaps the fastcgi process died), write-offset: 0 socket: tcp:127.0.0.1:9000

There appears to be a race because fcgi_write_request doesn't verify that the socket is connected/writable when
it is called in the CONNECT_DELAYED state.

The attached patch fixes the issue.


Files

patch-connect-race-mod_fastcgi.c (750 Bytes) patch-connect-race-mod_fastcgi.c patch to mod_fastcgi.c rr, 2011-07-26 21:33
test-connect-race.c (570 Bytes) test-connect-race.c test showing ENOTCONN during connect on FreeBSD rr, 2011-07-27 01:26
patch-connect-race-network_freebsd_sendfile.c (691 Bytes) patch-connect-race-network_freebsd_sendfile.c patch to treat ENOTCONN as not-yet-connected rr, 2011-07-27 01:26

Related issues 2 (0 open2 closed)

Related to Bug #2316: FreeBSD fastcgi broken: connection was dropped after accept()Missing Feedback2011-05-12Actions
Related to Bug #2121: fastcgi failover not workingMissing Feedback2009-12-16Actions
Actions #1

Updated by stbuehler over 12 years ago

  • Status changed from New to Invalid

not writable would result in EAGAIN, which is not recognized as "connection drop". and not all systems support poll...

Updated by rr over 12 years ago

writev() definitely returns ENOTCONN before the socket is connected. Try it yourself with the attached test.

Also attached a FreeBSD-specific patch to address issue as "EAGAIN".

Actions #3

Updated by stbuehler over 12 years ago

Actions #4

Updated by mouk.naj over 12 years ago

any chance of this patch making its way into lighttpd source tree? we been running it on a number of heavily loaded lighttpd servers on freebsd here at WhatsApp without any issues.

Actions #5

Updated by stbuehler over 12 years ago

The question is: can it happen that sendfile gets ENOTCONN as in "and won't be connected ever"? you just assume ENOTCONN means "not yet connected".

Actions #6

Updated by stbuehler almost 9 years ago

  • Target version set to 1.4.x
Actions #7

Updated by gstrauss about 8 years ago

Is the problem in this ticket still reproducible in FreeBSD 10?

mod_fastcgi is checking connect()ing socket for writability (POLLOUT) prior to attempting to write to socket. When detected as writable, mod_fastcgi checks getsockopt SO_ERROR to check that there was no socket error. This is an idiom I see quite often. Is there a different way to detect a connected socket on FreeBSD 8? The FreeBSD manpages suggest that what mod_fastcgi is doing is the right way to detect asynchronous connect has completed (or failed).

From FreeBSD man page for 'connect'
https://www.freebsd.org/cgi/man.cgi?query=connect&sektion=2&apropos=0&manpath=FreeBSD+10.2-RELEASE

     [EINPROGRESS]    The socket is non-blocking and the connection cannot
            be completed immediately.  It is possible to select(2)
            for completion by selecting the    socket for writing.

https://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2
     SO_ERROR returns any pending error    on the socket and clears the error
     status.  It may be    used to    check for asynchronous errors on connected
     datagram sockets or for other asynchronous    errors.

Actions #8

Updated by stbuehler about 8 years ago

  • Related to Bug #2316: FreeBSD fastcgi broken: connection was dropped after accept() added
Actions #9

Updated by gstrauss about 8 years ago

Please close ticket: Missing Feedback.

If this is still a problem, please reopen ticket and provide new details. Thank you.

Actions #10

Updated by gstrauss about 8 years ago

  • Status changed from Reopened to Missing Feedback

If this is still a problem, please reopen ticket and provide new details. Thank you.

Actions #11

Updated by stbuehler almost 8 years ago

  • Target version deleted (1.4.x)
Actions #12

Updated by gstrauss 4 months ago

  • Related to Bug #2121: fastcgi failover not working added
Actions

Also available in: Atom