Garrett Rooney [Tue, 7 Mar 2006 04:37:02 +0000 (04:37 +0000)]
Add support for starting multiple fastcgi processes listening on a
given socket. This somewhat makes up for our lack of a good way to
manage connections to a given proxy backend.
* support/fcgistarter.c
(main): Accept a new -N option that controls how many child procs
we fork off.
Garrett Rooney [Sun, 5 Mar 2006 21:43:58 +0000 (21:43 +0000)]
Add a first cut at a fastcgi starter program. This does the appropriate
daemonization and sockets magic to let a standard fastcgi program listen
on a TCP port.
Unfortunately due to some requirements of the FastCGI libraries and the
way APR process creation works this currently requires platform specific
code and thus only works on Unix systems.
Garrett Rooney [Sun, 5 Mar 2006 07:30:50 +0000 (07:30 +0000)]
Don't just hardcode 30 seconds as the poll timeout.
* modules/proxy/mod_proxy_fcgi.c
(dispatch): Use the worker timeout for our polls, falling back to the
old behavior of 30 seconds if there is no worker timeout set.
Garrett Rooney [Sun, 5 Mar 2006 07:08:28 +0000 (07:08 +0000)]
Fix up the path info in the balancer backend just like we do in the
fcgi backend. This lets Rails apps work under a balancer setup without
any hacks to Rails itself.
* modules/proxy/mod_proxy_balancer.c
(proxy_balancer_canon): Set r->path_info based on the path we got
from parsing the URL.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_canon): Remove the comment about balancer not setting
the path_info.
Garrett Rooney [Sun, 5 Mar 2006 04:33:44 +0000 (04:33 +0000)]
Stop holding open connections to the backend fastcgi processes. At
this point we lack a good way to manage them, and thus it's really
easy to end up with situations where you get weird timeouts because
other worker process are holding all the connections open.
This allows Rails applications to reliably work with mod_proxy_fcgi.
* modules/proxy/mod_proxy_fcgi.c
(dispatch): Add a timeout for our poll. This should be controlled
by a config option of some sort, but for now just hardcode it.
(proxy_fcgi_handler): Set close_on_recycle to 1, so we don't hold
open connections to the fastcgi processes.
Garrett Rooney [Sun, 5 Mar 2006 00:57:24 +0000 (00:57 +0000)]
Bring the debugging output up to date with the kind of things that are
actually being debugged at the moment. Also note a problem with the way
we handle the path info setup.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_canon): Log the filename and path info when we set them,
add a note that the path info stuff isn't being set if we're run in
a balancer setup, which needs to be fixed somehow.
(send_environment): Add an (ifdefed) call to log the environment vars
we send to the backend server.
(dump_header_to_log): Default to ifdefing this out, we're a bit beyond
bugs in the raw FCGI protocol at this point and it fills up the logs.
Jim Jagielski [Thu, 9 Feb 2006 16:51:22 +0000 (16:51 +0000)]
Document that we are being chunking in our
content passing, as compared to simply spooling
all the content in until clen == 0. Also, we
need to cleanup the brigade after each pass.
Garrett Rooney [Sun, 29 Jan 2006 01:19:47 +0000 (01:19 +0000)]
Now that the dispatch function handles the entire request there's no need
to create a long lived pool, we can use one that's local to the function.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_baton_t): Removed.
(dispatch): Use a local setaside pool instead of one from the baton.
(proxy_fcgi_handler): Don't bother creating a baton.
Garrett Rooney [Tue, 24 Jan 2006 06:21:09 +0000 (06:21 +0000)]
Clean up the end-of-headers detection code a bit. I'm still getting some
strange problems with really large numbers of headers, but I'm starting to
suspect that it's a problem with my FastCGI lib, not this module, and this
at least makes things shorter and a bit easier to read, along with fixing
one bug.
* modules/proxy/mod_proxy_fcgi.c
(handle_headers): Get rid of some cases that were not strictly needed.
Insert a case that was missed that screwed things up when there were
more than one header.
(dispatch): Move the 'done with headers' code into the preceding block,
add a note about a case that needs to be investigated.
Garrett Rooney [Mon, 23 Jan 2006 15:57:03 +0000 (15:57 +0000)]
Update the proxy worker stats when we read/write data from/to the back
end fastcgi process.
* modules/proxy/mod_proxy_fcgi.c
(send_data, get_data): New wrapper functions that do the sendv/recv
stuff and then update the proper statistics.
(send_begin_request, send_environment, dispatch): Use send_data/get_data.
Garrett Rooney [Mon, 23 Jan 2006 00:53:29 +0000 (00:53 +0000)]
Fix the code that detects the end of the headers in mod_proxy_fcgi. In
the old code, we'd fail to detect the end of the headers if they were split
over multiple fastcgi records, or if the cgi script used \n at the end of
each header instead of \r\n.
* modules/proxy/mod_proxy_fcgi.c
(HDR_STATE_READING_HEADERS,
HDR_STATE_GOT_CR,
HDR_STATE_GOT_CRLF,
HDR_STATE_GOT_CRLFCR,
HDR_STATE_GOT_LF,
HDR_STATE_DONE_WITH_HEADERS): Constants to track where we are in parsing
the end of the headers.
(handle_headers): Take the current parsing state as an argument, use a
state machine to detect the end of the headers instead of strstr.
(dispatch): Pass the state to handle_headers.
Garrett Rooney [Wed, 11 Jan 2006 04:07:56 +0000 (04:07 +0000)]
Change the FastCGI URL scheme to fcgi://.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_canon): Stop pretending unix domain sockets will need their
own url scheme.
(FCGI_SCHEME): New constant to describe the FastCGI proxy backend.
(proxy_fcgi_handler): Drop the fcgi-local stuff, use FCGI_SCHEME now that
we aren't worrying about multiple types of FastCGI workers.
Jim Jagielski [Mon, 9 Jan 2006 14:10:55 +0000 (14:10 +0000)]
Allow for "natural" usage of normal FCGI structs when logical, yet
still correctly handle cases where we need to ship those structs
over the wire, by transforming them from FCGI structs to
unsigned char arrays. Place the logic of mapping that
struct to the arrays in distinct functions, isolating
them.
Garrett Rooney [Mon, 9 Jan 2006 05:43:07 +0000 (05:43 +0000)]
After more comparison with existing mod_proxy backends, such as http
it seems clear that we're going to need to be able to specify arbitrary
portions of the URL that need to be added to the path info. Follow the
lead of mod_proxy_http and add the calculation of this into the canon
handler.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_canon): Add the path portion of the back end URL to the
path_info of the request, via the ap_proxy_canonenc function.
Garrett Rooney [Sun, 8 Jan 2006 04:48:50 +0000 (04:48 +0000)]
In theory, we now correctly implement all of the FastCGI protocol, so
there's no reason that request ids wouldn't be matching up. Until we
see an example of a request id mismatch error that is absolutely not
caused by an error in our parsing of the FastCGI protocol, we should
be able to go back to treating mismatches as errors.
* modules/proxy/mod_proxy_fcgi.c
(dispatch): Remove #ifdef that turned off treating rid mismatches as
fatal errors.
Garrett Rooney [Sat, 7 Jan 2006 21:37:40 +0000 (21:37 +0000)]
Make the handling of FastCGI request headers consistent. Previously, we
used a struct to hold the data when writing it, but read it into an array
when reading it. This meant that the knowledge of the header layout was
in two places. This change moves both sides to using an array, and adds
a set of #defines for the offsets into the array, so neither side can get
out of sync.
This also moves the logic for setting up the content length bytes into one
place, where before we had it in several places.
* modules/proxy/mod_proxy_fcgi.c
(fill_in_header): Take an array, not a struct pointer, and handle all
the contents of the header, not just the type and request id.
(send_begin_request, send_environment, dispatch): Update for new way
to fill in headers.
Garrett Rooney [Fri, 6 Jan 2006 03:51:43 +0000 (03:51 +0000)]
Read the FCGI_STDERR stream and log it to the error log. This will need
cleanup, but at least it keeps us from messing up the stream when we get
stuff written to stderr by the fastcgi process.
* modules/proxy/mod_proxy_fcgi.c
(dispatch): Move the plen recv down after the switch, so it gets done
for all cases that have padding. Read data for the FCGI_STDERR case
just like we do for FCGI_STDOUT, but write it to the log instead of
sending it to the client.
Garrett Rooney [Thu, 5 Jan 2006 05:24:43 +0000 (05:24 +0000)]
Make sure that we read the padding bytes in all cases. Also cut
down on some of the crazy verbose logging, since this seems to be
the problem we were trying to find.
* modules/proxy/mod_proxy_fcgi.c
(dispatch): Remove really verbose logging, move reading of the
padding bytes down to the end of the FCGI_STDOUT case.
Garrett Rooney [Wed, 4 Jan 2006 03:51:58 +0000 (03:51 +0000)]
Clean up record header parsing a bit. This may fix the problems some
people have seen where rid != request_id.
* modules/proxy/mod_proxy_fcgi.c
(dispatch): Stop initializing things we're just going to assign over
them later, initialize all of the rid and clen variables, and fix a
warning from passing an unsigned char array into apr_socket_recv by
adding a cast to char *.
Jim Jagielski [Tue, 3 Jan 2006 18:05:54 +0000 (18:05 +0000)]
Garret has a good point... even though we are sending the whole
struct, and assuming that it's following the correct format,
we should be extra careful when rec'ing the header info, and
ensure that each byte is followed one after another.
Jim Jagielski [Mon, 2 Jan 2006 16:52:58 +0000 (16:52 +0000)]
Avoid magic numbers. Since we are reading the header, let's
be explicit about it. Also removes the need to clean up
the readbuf again, and any potential for confusion on
what we are doing ;)
Paul Querna [Fri, 30 Dec 2005 20:59:30 +0000 (20:59 +0000)]
Handle reading fastcgi records with content length larger than AP_IOBUFSIZE.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_baton_t): New struct, holds per-connection data.
(dispatch): Set buckets aside into the scratch pool in the baton,
clearing it when we pass the baton on. Deal with the case where
the content length is larger than AP_IOBUFSIZE. Consistently use
sizeof when referring to the length of buffers. Explicitly null
terminate the read buffer after reading. Read the padding bytes
in a second pass to simplify logic.
(proxy_fcgi_handler): Create our baton and stash it in the connection's
data member.
Paul Querna [Thu, 29 Dec 2005 21:59:50 +0000 (21:59 +0000)]
Add support for reading FCGI_STDOUT and FCGI_END_REQUEST records from the
back end fastcgi process. This includes switching to a poll based dispatch
loop that handles interleaved reads and writes.
* modules/proxy/mod_proxy_fcgi.c
(MAX_INPUT_BYTES): Removed, we now use AP_IOBUFSIZE.
(handle_headers): New helper function for parsing headers out of the
response data.
(send_stdin): Removed, code incorporated into dispatch routine.
(dispatch): New, poll based dispatch loop that handles both reads and
writes.
(fcgi_do_request): Call new dispatch routine. Return OK if we get
through without errors.
Paul Querna [Tue, 27 Dec 2005 07:23:44 +0000 (07:23 +0000)]
Add support for sending the FASTCGI_STDIN stream of data to the fastcgi
process.
* modules/proxy/mod_proxy_fcgi.c
(fill_in_header): New helper function.
(send_begin_request, send_environment): Fix formatting, use fill_in_header.
(MAX_INPUT_BYTES): New constant.
(send_stdin): New function.
(fcgi_do_request): Send the body of the request via send_stdin.
Paul Querna [Mon, 26 Dec 2005 08:57:06 +0000 (08:57 +0000)]
Add support for sending the environment to the backend fastcgi process
to mod_proxy_fcgi.
* modules/proxy/mod_proxy_fcgi.c
(proxy_fcgi_canon): Remove unused variables, wrap a long line.
(send_begin_request): Helper function to send the FCGI_BEGIN_REQUEST
message.
(send_environment): Helper function to send the environment.
(fcgi_do_request): Use send_begin_request and send_environment.
Paul Querna [Sun, 18 Dec 2005 05:42:38 +0000 (05:42 +0000)]
Create a templte for a FastCGI proxy backend. It does not actually do much yet, but is the base for more development. I hope to work on this more tomorrow.
Joe Orton [Fri, 16 Dec 2005 13:08:32 +0000 (13:08 +0000)]
* modules/debug/mod_bucketeer.c (bucketeer_out_filter): Only pass on
the brigade if the pass delimiter is reached and not for any flush
delimiter; allows creating brigades with a flush bucket in the middle.
Fail if ap_pass_brigade() fails.
Ruediger Pluem [Sun, 11 Dec 2005 00:15:27 +0000 (00:15 +0000)]
* Move handling of backends that broke after the headers have been sent
into the proxy handler of mod_proxy.
This patch still sets r->connection->aborted to 1 which is currently
vetoed by Roy. Moving it from the scheme handler to the proxy handler
should ease the reimplementation of this, as the scheme handlers only
needs to return PROXY_BACKEND_BROKEN to signal the above situation to
the proxy handler.
mod_proxy.h: Add define for PROXY_BACKEND_BROKEN
mod_proxy.c: Handle PROXY_BACKEND_BROKEN in proxy handler
mod_proxy_http.c: Sent back PROXY_BACKEND_BROKEN if backend broke
after we sent the headers.
Jim Jagielski [Thu, 1 Dec 2005 13:50:11 +0000 (13:50 +0000)]
Until we determine whether we should dip into the connection
pool each time, rearrange the logic to avoid a double
check which is unneeded. No matter what (if it's reusable or
not) a null conn->hostname needs to be set. At that
point it doesn't matter if we're not reusing it or
if the string comparison happens, since what we
would do in that case has already been done.