Frank Meier wrote:
Hi
I'm working with a proprietary apache module which communicates (through
a socket) with another backend application (I have the C source code of
the module). I've now found out, when the client closes the http
connection during a request, the module does not "see" that the client
has disconnected. In some cases the request is just finished, but with
larger requests (larger amount of data from backend), the module keeps hanging in the ap_rwrite() or ap_rflush() function. This is only resolved if a timeout (default 300s, timeout directive in httpd.conf) occurs. I think the tx-buffer of the socket is filled and then the
write/flush function blocks.

Frank,

In Apache 2.2 your module should not need to communicate directly with the client. Instead, pass your output into the bucket brigade. Something like this (Note: sock is a socket connection to an external host):

       bb = apr_brigade_create(r->pool, c->bucket_alloc);

       /* Put the body of the reply into the bucket brigade */
       b = apr_bucket_socket_create(sock, c->bucket_alloc);
       APR_BRIGADE_INSERT_TAIL(bb, b);
       b = apr_bucket_eos_create(c->bucket_alloc);
       APR_BRIGADE_INSERT_TAIL(bb, b);
       status = ap_pass_brigade(r->output_filters, bb);
       if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "ap_pass_brigade failed");
           apr_socket_close(sock);
           return HTTP_INTERNAL_SERVER_ERROR;
       }

This code passes the socket into the bucket brigade which takes care of all the client communication. In addition, it allows for other modules to still act upon the output data.


I've read in "the Apache Modules Book" (p.138)

Try Nick's book ( http://books.google.com/books?id=HTo_AmTpQPMC ) as it is geared toward the newer Apache releases. Chances are the module you inherited has not been properly updated to the new Apache standards.

Regards,

Chris Kukuchka
Sequoia Group, Inc.


Reply via email to