> Date: Thu, 31 Mar 2011 19:25:58 +0200
> Subject: Re: cpu 100%
> From: sor...@gmail.com
> To: modules-dev@httpd.apache.org
>
> On Thu, Mar 31, 2011 at 19:10, Niko Goutte <ngou...@hotmail.com> wrote:
> >
> >> Date: Thu, 31 Mar 2011 18:22:34 +0200
> >> Subject: Re: cpu 100%
> >> From: sor...@gmail.com
> >> To: modules-dev@httpd.apache.org
> >>
> >> > -------------------------------------------------------------------------------------------------------------------------------
> >> > HERE IS:
> >> > #include <httpd.h>
> >> > #include <http_config.h>
> >> > #include <http_protocol.h>
> >> > #include <http_request.h>
> >> > #include <http_log.h>
> >> > #include <ap_compat.h>
> >> > #include <apr_buckets.h>
> >> > #include <apr_strings.h>
> >> >
> >> >
> >> > #define ASE_FILE_SIZE 512000
> >> > #define ASE_BUFFER_SIZE 104858
> >> >
> >> > module AP_MODULE_DECLARE_DATA ase_mod_module;
> >> > #define ASE_MOD_HANDLER "ase-mod.extensions"
> >> >
> >> > static int ase_mod_handler(request_rec *r)
> >> > {
> >> > apr_status_t rv = APR_SUCCESS;
> >> > apr_bucket_brigade* bb = NULL;;
> >> > apr_bucket* b = NULL;;
> >> > char filename[256];
> >> >
> >> > /* First, some housekeeping. */
> >> > if (((!r->handler) != 0)|| (strcmp(r->handler, ASE_MOD_HANDLER)))
> >> > {
> >> > /* r->handler wasn't "ase_mod", so it's none of our business */
> >> > ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,"Decline
> >> > processing file %s is not %s and handler %s",
> >> > r->filename,ASE_MOD_HANDLER,r->handler);
> >> > return DECLINED;
> >> > }
> >> >
> >> > if (r->method_number != M_GET)
> >> > {
> >> > ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,"Error
> >> > METHOD_NOT_ALLOWED (%d)",r->method_number);
> >> > return HTTP_METHOD_NOT_ALLOWED;
> >> > }
> >> >
> >> > ap_log_error(APLOG_MARK, APLOG_INFO, 0,
> >> > r->server,"%s",r->the_request);
> >> >
> >> > // Construct filename
> >> > strncpy(filename, r->filename, sizeof(filename) / sizeof(char) - 1);
> >> > filename[sizeof(filename) / sizeof(char) - 1] = '\0';
> >> >
> >> > ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,"filename =
> >> > %s",filename);
> >> >
> >> > int DataSize = ASE_FILE_SIZE;
> >> >
> >> > ap_set_content_type(r, "video/ase");
> >> >
> >> > ap_update_mtime(r, r->finfo.mtime);
> >> > ap_set_last_modified(r);
> >> >
> >> > apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
> >> >
> >> > r->vlist_validator = apr_pstrcat(r->pool, "X",apr_itoa(r->pool,
> >> > DataSize), "\"", NULL);
> >> > ap_set_etag(r);
> >> >
> >> > char content_range[64];
> >> > sprintf(content_range,"bytes
> >> > %d-%d/%d",0,ASE_FILE_SIZE-1,ASE_FILE_SIZE);
> >> > ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,"Add content range
> >> > %s",content_range);
> >> > apr_table_setn(r->headers_out, "Content-Range",content_range);
> >> >
> >> > r->status = HTTP_OK;
> >> >
> >> > bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
> >> > char* Buf;
> >> > Buf = apr_palloc(r->pool,ASE_BUFFER_SIZE);
> >> > int size = ASE_BUFFER_SIZE;
> >> >
> >> > unsigned int count = 0;
> >> > while(DataSize>0)
> >> > {
> >> > if((DataSize - size)<0)
> >> > {
> >> > size = DataSize;
> >> > }
> >> >
> >> > memset(Buf,count,size);
> >> >
> >> > b = apr_bucket_pool_create(Buf ,size, r->pool,
> >> > r->connection->bucket_alloc) ;
> >> >
> >> > APR_BRIGADE_INSERT_TAIL(bb, b);
> >> >
> >> > APR_BRIGADE_INSERT_TAIL(bb,apr_bucket_flush_create(bb->bucket_alloc));
> >> >
> >> > if(DataSize <= size)
> >> > {
> >> >
> >> > APR_BRIGADE_INSERT_TAIL(bb,apr_bucket_eos_create(bb->bucket_alloc));
> >> > ap_log_error(APLOG_MARK, APLOG_INFO, 0,
> >> > r->server,"APR_BRIGADE_INSERT_TAIL EOS Bucket");
> >> > }
> >> >
> >> > rv = ap_pass_brigade(r->output_filters, bb);
> >> >
> >> > if (rv != APR_SUCCESS)
> >> > {
> >> > ap_log_error(APLOG_MARK, APLOG_ERR, 0,
> >> > r->server,"HTTP_INTERNAL_SERVER_ERROR ap_pass_brigade ");
> >> > r->status = HTTP_INTERNAL_SERVER_ERROR;
> >> > return r->status;
> >> > }
> >> >
> >> > DataSize = DataSize - size;
> >> > count++;
> >> > ap_log_error(APLOG_MARK, APLOG_INFO, 0,
> >> > r->server,"ap_pass_brigade, DataSize = %d and Size = %d",DataSize, size
> >> > );
> >> >
> >> > apr_brigade_cleanup(bb);
> >> > }
> >> >
> >> > ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,"Out of While");
> >> >
> >> > apr_bucket_delete(b);
> >>
> >> Try to remove this apr_bucket_delete from here. apr_brigade_cleanup in
> >> the while loop deletes the buckets in the brigade. I think you delete
> >> b twice.
> >>
> >> Sorin
> >
> >
> >
> > That's true, I've no more the segmentation fault but in wireshark capture
> > on the client side, I've this error message only in prefork mode:
> >
> >
> >
> > GET /mmrk_dummy_2mbps_10s.mmrk?TxId=8 HTTP/1.1
> > Range: bytes=0-511999
> > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5
> > OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> > Host: 192.X.X.X
> >
> > Accept: */*
> > Cache-Control: no-cache
> >
> > HTTP/1.1 200 OK
> > Date: Thu, 31 Mar 2011 16:53:57 GMT
> > Server: Apache/2.2.3 (CentOS)
> > Last-Modified: Fri, 25 Mar 2011 11:18:16 GMT
> > Accept-Ranges: bytes
> > ETag: "12a8006-4e2e90-49f4cc0186e00;512000"
> > Content-Range: bytes 0-511999/512000
> > Connection: close
> > Transfer-Encoding: chunked
> > Content-Type: video/ase
> >
> > 1999a + DATA
> > 1999a + DATA
> > 1999a + DATA
> > 1999a + DATA
> > 0
> >
> > 23e
> > <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
> > <html><head>
> > <title>200 OK</title>
> > </head><body>
> > <h1>OK</h1>
> > <p>The server encountered an internal error or
> > misconfiguration and was unable to complete
> > your request.</p>
> > <p>Please contact the server administrator,
> > root@localhost and inform them of the time the error occurred,
> > and anything you might have done that may have
> > caused the error.</p>
> > <p>More information about this error may be available
> > in the server error log.</p>
> > <hr>
> > <address>Apache/2.2.3 (CentOS) Server at 192.X.X.X Port 80</address>
> > </body></html>
> >
>
> Try to exit with return OK instead of return r->status from your handler.
>
> Sorin
Well done !!
It works fine now.
Thank you.
Nicolas.