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

Dave Pifke dave at bebo.com
Mon Jun 19 22:44:30 EDT 2006


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?

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;
  }



-- 
Dave Pifke, dave at bebo.com
Sr. System Administrator, Bebo Inc.
www.bebo.com





More information about the Modules mailing list