httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Moacir Schmidt" <>
Subject ap_get_brigade hangs when submitting a muitipart/form-data
Date Thu, 14 Feb 2008 18:53:32 GMT
Hi, everybody!

I'm trying to develop an 'uploader'  dso module to handle file
submissions from client browsers. The code worked well on win32 but on
debian hangs with files which size is over 22k.

Debugging my component shows me that the function ap_get_brigade slows
down after two or three loop interactions.

I isolated the problem in a 'helloworld' packet as follows:
index.htm: sample submit form:
<form name="teste" enctype="multipart/form-data" method="post"
<input type=file name="arquivo" style="left:0;top:0;width:271; height:21;">
<input type=submit name="enviar" style="position:absolute;left:0;top:50">
t02.c: module source code:
#include <httpd.h>
#include <http_log.h>
#include <http_protocol.h>
#include <http_config.h>
// most of this code came from mod_cgi.c
static int helloworld_handler(request_rec* r)
  if (!r->handler || strcmp(r->handler, "helloworld"))
    return DECLINED;
  apr_bucket_brigade *bb;
  int seen_eos, child_stopped_reading;
  bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
  seen_eos = 0;
  child_stopped_reading = 0;
  apr_status_t rv;
  ap_set_content_type(r, "text/html;charset=ascii"); // just to see
something on the browser
  do {
    apr_bucket *bucket;

    // ap_get_brigade slows down here after some loop iteractions when file
submitted is larger than 22kb
    rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES,
    //   ^^^^^^^^^^^^^^
    if (rv != APR_SUCCESS) {
    for (bucket = APR_BRIGADE_FIRST(bb);
    bucket != APR_BRIGADE_SENTINEL(bb);
    bucket = APR_BUCKET_NEXT(bucket)) {
       apr_size_t len;
       const char *data;
       if (APR_BUCKET_IS_EOS(bucket)) {
         seen_eos = 1;

       if (APR_BUCKET_IS_FLUSH(bucket)) {

       if (child_stopped_reading) {
       rv = apr_bucket_read(bucket, &data, &len, APR_BLOCK_READ);
       if (rv != APR_SUCCESS) {
          child_stopped_reading = 1;
       ap_rputs(data,r); // just do see something on the browser
  }  while (!seen_eos);
  return OK;
static void register_hooks(apr_pool_t* pool)
  ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
module AP_MODULE_DECLARE_DATA helloworld_module = {
PIC_12930.jpg: a sample file to upload that hangs ap_get_brigade (attached)

to reproduce the problem:

1) Compile module with apxs
apxs -c t02.c
apxs -ie

2) configure httpd.conf
LoadModule helloworld_module modules/
<Location /helloworld>
 SetHandler helloworld

3) start apache with -X
httpd -k start -X

4) open index.htm on a client browser and submit file PIC_12930. jpg.
You'll receive no response from server on a reasonable time. Debugging
this process reveal me that the problem was on ap_get_brigade function

I don't know if there is something wrong with my code or if there is
some bug on ap_get_brigade function. Any help will be very appreciate!

Thanks to everybody!

Important information:

Apache: version: 2.2.8
OS: Debian GNU Linux (kernel 2.4 or 2.6. it happens on both)

  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message