ap_get_brigade hangs when submitting a muitipart/form-data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
t02.c: module source code;
PIC_12930.jpg: a sample file to upload that hangs ap_get_brigade

to reproduce the problem:

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

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

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)
#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, APR_BLOCK_READ, 8192); 
    //   ^^^^^^^^^^^^^^
    if (rv != APR_SUCCESS) { 
      return HTTP_INTERNAL_SERVER_ERROR;
    } 

    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;
         break;
       }
											   
       if (APR_BUCKET_IS_FLUSH(bucket)) {
          continue;
       }
   
       if (child_stopped_reading) {
          continue;
       }

       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
    }
    apr_brigade_cleanup(bb);
  }  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 = {
  STANDARD20_MODULE_STUFF,
  NULL,
  NULL,
  NULL,
  NULL,
  NULL,
  register_hooks
};

Attachment: PIC_12930.jpg
Description: JPEG image

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux