apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: File descriptor leak with mpm-event / apr file bucket cleanup
Date Tue, 18 May 2010 05:52:46 GMT
On 17.05.2010 23:11, Stefan Fritsch wrote:
> Hi,
> 
> in Wicklow, Rainer pointed out a problem with mpm event (in trunk): 
> File descriptors from file buckets are not closed as soon as the file 
> has been sent completely, but instead are only closed when the 
> connection is closed.
> 
> The core output filter setasides the file buckets into the connection 
> pool. The problem is that apr-util does not close the file when the 
> bucket is destroyed, but instead depends on the pool being destroyed, 
> too. I think this is a bug in apr-util. The patch below fixes the 
> problem. Do you agree or should this somehow be fixed in the core 
> output filter?
> 
> Of course, it is possible that some apr-util users depend on this 
> strange behaviour.
> 
> Cheers,
> Stefan
> 
> --- buckets/apr_buckets_file.c.dist +0200
> +++ buckets/apr_buckets_file.c
> @@ -34,8 +34,7 @@
>      apr_bucket_file *f = data;
>  
>      if (apr_bucket_shared_destroy(f)) {
> -        /* no need to close the file here; it will get
> -         * done automatically when the pool gets cleaned up */
> +        apr_file_close(f->fd);
>          apr_bucket_free(f);
>      }
>  }
> 
> 

I guess this would be wrong. Think of the following scenario.

1. A brigade with a file bucket.
2. The file bucket is split into two file buckets during processing in the
   filter chain.
3. The first bucket is processed and destroyed. This would leave the second
   file bucket with an closed file descriptor.

So if you want to close this fd you IMHO would need to do some refcounting
and only close it if no other filebucket still references it.

Regards

RĂ¼diger




Mime
View raw message