]> err.no Git - varnish/commitdiff
Minimize a race when looking up addresses for backends.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 7 Aug 2007 10:27:34 +0000 (10:27 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 7 Aug 2007 10:27:34 +0000 (10:27 +0000)
The race is not closed however, proper locking needs to be thought out.

An XXX comment documents this for now.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1809 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_backend.c

index 0e92976299bbefec01686c4e92418a5deb2d5b27..ed2a23ef0080f0009b9ecf6139e673955b4836a9 100644 (file)
@@ -116,20 +116,20 @@ vbe_new_conn(void)
        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 @@ vbe_lookup(struct backend *bp)
                printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */
                return;
        }
+       old = bp->addr;
        bp->last_addr = res;
        bp->addr = res;
+       if (old != NULL)
+               freeaddrinfo(old);
 }
 
 /*--------------------------------------------------------------------*/