You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2005/04/23 09:12:05 UTC

DO NOT REPLY [Bug 34589] New: - continious grow of memory usage when running simple module with never-ending connections

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=34589>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=34589

           Summary: continious grow of memory usage when running simple
                    module with never-ending connections
           Product: Apache httpd-2.0
           Version: 2.0.54
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: All
        AssignedTo: bugs@httpd.apache.org
        ReportedBy: norair@freenet.am


When running apache versions 2.0.52 2.0.53, 2.0.54 with following simple module
memory usage continuing its grow until all memory and swap is used, after which
system killing processes to free resources. I've tried this module with worker
and prefork mpm compiled httpd's on a 2.4 and 2.6 kernel running machines
(debian and fedora core).
Please, try to establish 500 - 1000 connections to module below and see what
happens with memory usage. Apache just killing the system when occupy all
available memory and swap space. In case of low number of connections, memory
usage still grow but not so fast, so will be noticed after certain time interval

module text:
--------------------------

#include "httpd.h"
#include "http_config.h"

#include <time.h>
#include <sys/time.h>
#include <stdio_ext.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inc/sp.h"



#define DEFAULT_ENCTYPE "application/x-www-form-urlencoded"


int start_receive(request_rec *r)
{
	int ret;

        while(TRUE)
	{
          ret = ap_rprintf (r, "888839457349857394573495888888888888888\r\n");
	  ret = ap_rflush(r);
	  sleep(1);  
        }
	
	return 0;
}

/*
 * This function is registered as a handler for HTTP methods and will
 * therefore be invoked for all GET requests (and others).  Regardless
 * of the request type, this function simply sends a message to
 * STDERR (which httpd redirects to logs/error_log).  A real module
 * would do *alot* more at this point.
 */

static int receiver_method_handler (request_rec *r)
{
    char* req;
    int	 ret;
    apr_table_t*	table;  

    req = r->the_request;
    if (strstr(req, "messages") == NULL) {
       return DECLINED;
    }
    
    table = apr_table_make(r->pool, 8);
   
    ret = read_post(r, &table);
    
    start_receive(r);

    return OK;
}

/*
 * This function is a callback and it declares what other functions
 * should be called for request processing and configuration requests.
 * This callback function declares the Handlers for other events.
 */
static void register_hooks (apr_pool_t *p)
{
	// I think this is the call to make to register a handler for method calls (GET
PUT et. al.).
	// We will ask to be last so that the comment has a higher tendency to
	// go at the end.
	ap_hook_handler(receiver_method_handler, NULL, NULL, APR_HOOK_LAST);
}

/*
 * Declare and populate the module's data structure.  The
 * name of this structure ('rec_mod') is important - it
 * must match the name of the module.  This structure is the
 * only "glue" between the httpd core and the module.
 */
module AP_MODULE_DECLARE_DATA receiver_module =
{
	// Only one callback function is provided.  Real
	// modules will need to declare callback functions for
	// server/directory configuration, configuration merging
	// and other tasks.
	STANDARD20_MODULE_STUFF,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	register_hooks,			/* callback for registering hooks */
};


static int util_read(request_rec *r, const char **rbuf)
{
   int rc;
   if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) {
      return rc;
   }
   if (ap_should_client_block(r)) {
     char argsbuffer[HUGE_STRING_LEN];
     int rsize, len_read, rpos=0;
     long length = r->remaining;
     *rbuf = apr_pcalloc(r->pool, length + 1);
//     ap_hard_timeout("util_read", r);
     while ((len_read = ap_get_client_block(r, argsbuffer, sizeof(argsbuffer)))
> 0) {
//       ap_reset_timeout(r);
       if ((rpos + len_read) > length) {
         rsize = length - rpos;
       }
       else {
         rsize = len_read;
       }
       memcpy((char*)*rbuf + rpos, argsbuffer, rsize);
       rpos += rsize;
    }
//    ap_kill_timeout(r);
  }
  return rc;
}


static int read_post(request_rec *r, apr_table_t **tab)
{
   const char *data;
   const char *key, *val, *type;
   int rc = OK;
   if(r->method_number != M_POST) {
     return rc;
   }
   type = apr_table_get(r->headers_in, "Content-Type");
   if(strcasecmp(type, DEFAULT_ENCTYPE) != 0) {
         return DECLINED;
   }
   if((rc = util_read(r, &data)) != OK) {
     return rc;
   }
   if(*tab) {
     apr_table_clear(*tab);
   }
   else {
     *tab = apr_table_make(r->pool, 8);
   }
   while(*data && (val = ap_getword(r->pool, &data, '&'))) {       
     key = ap_getword(r->pool, &val, '=');
     ap_unescape_url((char*)key);
     ap_unescape_url((char*)val);
     apr_table_merge(*tab, key, val);
   }
   return OK;
}

----------------

Thank You very much!

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org