<p>hi, i am web server(nginx) module developer. <br>my nginx modules has a major problem.<br>maybe... this problem is seem to nginx core bug.<br>i hope this is my module problem. Because, i wish the problem to be settled soon.</p>
<p><strong>my module function:</strong><br>large post data logging from specified file(nginx.conf setting : /home1/test_access.log)</p><div><strong>problem:</strong><br>constant use of memory(nginx-1.2.2 , same situation)</div>
<div> <img alt="º»¹® À̹ÌÁö 1" src="cid:ii_13a2a29f77fb4488"></div><div> </div><div> </div><div><strong>nginx environment:</strong><br>./nginx -V<br>nginx version: nginx/1.0.14<br>built by gcc 4.1.2 20080704 (Red Hat 4.1.2-44)<br>
configure arguments: --prefix=/home1/apps/nginx --with-http_gzip_static_module --with-http_stub_status_module --add-module=/home1/apps/nginx-1.0.14/modules<strong>/testmodule</strong></div><div><strong></strong> </div><div>
<strong>server environment:</strong><br>uname -a<br>Linux test.server 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux<br></div><div><strong>/etc/redhat-release:</strong><br>CentOS release 5.3 (Final)</div>
<p><strong>nginx.conf:</strong><br>worker_processes  2;<br>worker_cpu_affinity 01 10;<br>worker_rlimit_core 500M;<br>working_directory /home1/cores/;<br>worker_rlimit_nofile 15000;<br>...<br>events {<br>        worker_connections  15000;<br>
        accept_mutex on;<br>}<br>...<br>http {<br> client_body_in_single_buffer on;<br> client_body_in_file_only off;<br> client_body_buffer_size 10m;<br>        client_max_body_size 10m;<br>        client_header_buffer_size 10m;<br>
        server {<br>                listen       80;<br>                server_name  <a href="http://test.test.com">test.test.com</a>;<br>                location = /test {<br>                        testaccess_log /home1/test_access.log;<br>
   ...<br>                }<br>  ...<br> }<br>}<br>...</p><p><strong> my module source code :</strong><br>static int ngx_testmodule_log_write(ngx_http_request_t *r, char * content, unsigned int content_size)<br>{<br> this function is file writting...<br>
}</p><p>void<br>ngx_testmodule_post_read_request_body(ngx_http_request_t *r)<br>{<br>        ngx_int_t totalreadsize;<br>        ngx_int_t movepos;</p><p>        ngx_chain_t * cl=NULL;<br>        ngx_chain_t * cl2=NULL;<br>
        ngx_buf_t * buf=NULL;<br>        char * container=NULL;<br>        ngx_http_testmodule_conf_t * pConfig = NULL;<br>        int split_returnvalue;<br>        pConfig = ngx_http_get_module_loc_conf(r, ngx_http_testmodule_module);</p>
<p>        if(r->request_body == NULL || r->request_body->bufs == NULL || r->request_body->bufs->buf == NULL)<br>        {<br>                ngx_http_finalize_request(r, NGX_DONE);<br>                return;<br>
        }</p><p>        cl = r->request_body->bufs;<br>        if(cl->next == NULL)<br>        {<br>buf = cl->buf;<br>                totalreadsize = buf->last-buf->pos;<br>                if(totalreadsize > 0)<br>
                {<br>                        container = (char *)ngx_pcalloc(r->pool, totalreadsize+1);<br>                        if(container == NULL)<br>                        {<br>                                ngx_http_finalize_request(r, NGX_DONE);<br>
                                return;<br>                        }<br>                        memcpy(container, (char *)buf->pos, buf->last-buf->pos);<br>                        *(container+(buf->last-buf->pos)) = '\0';<br>
                }<br>                else<br>                {<br>                        ngx_http_finalize_request(r, NGX_DONE);<br>                        return;<br>                }<br>        }<br>        else<br>        {<br>
                fprintf(stderr, "=====MULTI BUFFER=====\n");<br>                totalreadsize = 0;<br>                cl2 = cl;<br>                while(cl2)<br>                {<br>                        totalreadsize += cl2->buf->last - cl2->buf->pos;<br>
                        cl2 = cl2->next;<br>                }<br>                if(totalreadsize > 0)<br>                {<br>                        container = (char *)ngx_pcalloc(r->pool, totalreadsize+1);<br>
                        if(container == NULL)<br>                        {<br>                                ngx_http_finalize_request(r, NGX_DONE);<br>                                return;<br>                        }</p>
<p>                        movepos = 0;<br>                        while(cl)<br>                        {<br>                                memcpy(container + movepos, (char *)cl->buf->pos, cl->buf->last - cl->buf->pos);<br>
                                movepos += (cl->buf->last - cl->buf->pos);<br>                                cl = cl->next;<br>                        }<br>                        *(container + movepos) = '\0';<br>
                }<br>                else<br>                {<br>                                ngx_http_finalize_request(r, NGX_DONE);<br>                                return;<br>                }</p><p>                if(totalreadsize != movepos)<br>
                {<br>                        ngx_http_finalize_request(r, NGX_DONE);<br>                        return;<br>                }<br>        }</p><p>        split_returnvalue = ngx_testmodule_log_write(r, container, totalreadsize);<br>
        ngx_http_finalize_request(r, NGX_DONE);<br>        return;</p><p>}</p><p>ngx_http_testmodule_handler(ngx_http_request_t *r)<br>{<br>if (!(r->method & NGX_HTTP_POST)) {<br>                return NGX_HTTP_NOT_ALLOWED;<br>
        }<br>        else if(!pConfig->enable) {<br>                return NGX_DECLINED;<br>        }</p><p>        rc_post = ngx_http_read_client_request_body(r, ngx_testmodule_post_read_request_body);</p><p>        ngx_testmodule_resheader(r);<br>
        ...<br>        return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_text_type, &cv);<br>}</p><p><br>i have tested my nginx module. but... i don't know.. difficult problem..<br>i am turning to you for help.</p>
<p> </p>