r2137 - in branches/1.1: . bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Fri Oct 19 13:21:06 CEST 2007


Author: des
Date: 2007-10-19 13:21:06 +0200 (Fri, 19 Oct 2007)
New Revision: 2137

Modified:
   branches/1.1/
   branches/1.1/bin/varnishd/cache_backend.c
Log:
Merged revisions 1809 via svnmerge from 
svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache

........
  r1809 | phk | 2007-08-07 12:27:34 +0200 (Tue, 07 Aug 2007) | 7 lines
  
  Minimize a race when looking up addresses for backends.
  
  The race is not closed however, proper locking needs to be thought out.
  
  An XXX comment documents this for now.
........



Property changes on: branches/1.1
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk/varnish-cache:1-1722,1727-1729,1733,1738,1743-1777,1779-1798,1800-1808,1810-1815,1817,1819,1823,1830-1838,1846,1853-1855,1857-1859,1862,1865-1868,1871-1880,1883-1884,1886,1896,1898,1902-1905,1907,1909,1912-1916,1920-1928,1935-1939,1941-1949,1955,1957-1958,1967-1968,1970-1974,1976-1977,1984,1986-1989,1991-1998,2032-2033,2133
   + /trunk/varnish-cache:1-1722,1727-1729,1733,1738,1743-1777,1779-1798,1800-1815,1817,1819,1823,1830-1838,1846,1853-1855,1857-1859,1862,1865-1868,1871-1880,1883-1884,1886,1896,1898,1902-1905,1907,1909,1912-1916,1920-1928,1935-1939,1941-1949,1955,1957-1958,1967-1968,1970-1974,1976-1977,1984,1986-1989,1991-1998,2032-2033,2133

Modified: branches/1.1/bin/varnishd/cache_backend.c
===================================================================
--- branches/1.1/bin/varnishd/cache_backend.c	2007-10-19 11:20:15 UTC (rev 2136)
+++ branches/1.1/bin/varnishd/cache_backend.c	2007-10-19 11:21:06 UTC (rev 2137)
@@ -116,20 +116,20 @@
 	return (vbc);
 }
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * XXX: There is a race here, we need to lock the replacement of the
+ * XXX: resolved addresses, or some other thread might try to access
+ * XXX: them while/during/after we changed them.
+ * XXX: preferably, we should make a copy to the vbe while we hold a
+ * XXX: lock anyway.
+ */
 
 static void
 vbe_lookup(struct backend *bp)
 {
-	struct addrinfo *res, hint;
+	struct addrinfo *res, hint, *old;
 	int error;
 
-	if (bp->addr != NULL) {
-		freeaddrinfo(bp->addr);
-		bp->addr = NULL;
-		bp->last_addr = NULL;
-	}
-
 	memset(&hint, 0, sizeof hint);
 	hint.ai_family = PF_UNSPEC;
 	hint.ai_socktype = SOCK_STREAM;
@@ -144,8 +144,11 @@
 		printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */
 		return;
 	}
+	old = bp->addr;
 	bp->last_addr = res;
 	bp->addr = res;
+	if (old != NULL)
+		freeaddrinfo(old);
 }
 
 /*--------------------------------------------------------------------*/




More information about the varnish-commit mailing list