[Modules] PATCH: apr_memcache doesn't seem to close connections

Paul Querna chip at outoforder.cc
Mon Jun 19 22:48:35 EDT 2006


Dave Pifke wrote:
> In playing with apr_memcache, I've noticed that it never seems to close
> connections to memcached.  Looking at the source (version 0.7.0), it
> would appear that mc_conn_destruct() is supposed to do this... but doesn't.
> 
> The following patch implements this functionality and seems to solve the
> problem on this end.  Sans patch, my memcached stats output would report
> tens of thousands of curr_connections (up to the max number of file
> descriptors for the memcached process).  After applying it, I'm seeing
> much more reasonable numbers.
> 
> (I'm using the hmax and smax parameters for apr_reslist_create to 
> dynamically allocate connections.)
> 
> Comments?

Thanks, I think this is a good idea.

APR memcache is now actually part of APR-Util:
http://svn.apache.org/repos/asf/apr/apr-util/trunk/memcache/apr_memcache.c

There are already a couple bug fixes in that version.

Would you mind posting this patch on dev at apr.apache.org?
http://apr.apache.org/mailing-lists.html

Thanks,

-Paul


> Index: apr_memcache.c
> ===================================================================
> --- apr_memcache.c      (revision 467)
> +++ apr_memcache.c      (revision 468)
> @@ -70,6 +70,9 @@
>  #define MC_STATS "stats"
>  #define MC_STATS_LEN (sizeof(MC_STATS)-1)
> 
> +#define MC_QUIT "quit"
> +#define MC_QUIT_LEN (sizeof(MC_QUIT)-1)
> +
>  /* Strings for Server Replies */
> 
>  #define MS_STORED "STORED"
> @@ -303,9 +306,20 @@
>  static apr_status_t
>  mc_conn_destruct(void *conn_, void *params, apr_pool_t * pool)
>  {
> -/*    apr_memcache_conn_t *conn = conn_;*/
> +    apr_memcache_conn_t *conn = conn_;
> +    struct iovec vec[2];
> +    apr_size_t written;
> +
> +    /* quit\r\n */
> +    vec[0].iov_base = MC_QUIT;
> +    vec[0].iov_len = MC_QUIT_LEN;
> +
> +    vec[1].iov_base = MC_EOL;
> +    vec[1].iov_len = MC_EOL_LEN;
> 
> -/*    apr_pool_destroy(conn->p); */
> +    /* Return values not checked. */
> +    apr_socket_sendv(conn->sock, vec, 2, &written);
> +    apr_socket_close(conn->sock);
> 
>      return APR_SUCCESS;
>  }
> 
> 
> 




More information about the Modules mailing list