[3.0] 6d74c0e Always pull the local address of the socket out right away.

Martin Blix Grydeland martin at varnish-cache.org
Fri Nov 22 12:54:56 CET 2013


commit 6d74c0e41d01d58d38550ce1652c257268719eb3
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Nov 20 13:52:00 2013 +0100

    Always pull the local address of the socket out right away.
    
    Fixes: #1376

diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 790ed62..c307b7b 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -178,8 +178,8 @@ VCA_Prep(struct sess *sp)
 	    addr, sizeof addr, port, sizeof port);
 	sp->addr = WS_Dup(sp->ws, addr);
 	sp->port = WS_Dup(sp->ws, port);
+	AZ(getsockname(sp->fd, (void*)sp->mysockaddr, &sp->mysockaddrlen));
 	if (params->log_local_addr) {
-		AZ(getsockname(sp->fd, (void*)sp->mysockaddr, &sp->mysockaddrlen));
 		VTCP_name(sp->mysockaddr, sp->mysockaddrlen,
 		    addr, sizeof addr, port, sizeof port);
 		VSL(SLT_SessionOpen, sp->fd, "%s %s %s %s",
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index 189d8e9..780a1e0 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -466,12 +466,6 @@ VRT_r_client_ip(const struct sess *sp)
 struct sockaddr_storage *
 VRT_r_server_ip(struct sess *sp)
 {
-	int i;
-
-	if (sp->mysockaddr->ss_family == AF_UNSPEC) {
-		i = getsockname(sp->fd, (void*)sp->mysockaddr, &sp->mysockaddrlen);
-		assert(VTCP_Check(i));
-	}
 
 	return (sp->mysockaddr);
 }
diff --git a/bin/varnishtest/tests/r01376.vtc b/bin/varnishtest/tests/r01376.vtc
new file mode 100644
index 0000000..9bc3d30
--- /dev/null
+++ b/bin/varnishtest/tests/r01376.vtc
@@ -0,0 +1,46 @@
+varnishtest "#1376 - server.ip initialization and ESI child"
+
+server s1 {
+	rxreq
+	txresp -body {<esi:include src="/foo"/><esi:include src="/bar"/>}
+
+	rxreq
+	expect req.url == "/foo"
+	sema r1 sync 2
+	# Send large body to closed socket. This should cause a write error,
+	# closing the socket also in the varnishd end
+	txresp -bodylen 1048576
+
+	rxreq
+	expect req.url == "/bar"
+	txresp -body "[bar]"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		if (req.url == "/bar") {
+			# Test getting the server ip on a closed socket
+			set req.http.test = server.ip;
+		}
+	}
+	sub vcl_fetch {
+		if (req.url == "/") {
+			set beresp.do_esi = true;
+		}
+	}
+} -start
+
+client c1 {
+	txreq -hdr "Host: foo"
+	rxresp -no_obj
+	# Closes connection
+} -run
+
+sema r1 sync 2
+
+# Try again to make sure varnishd didn't die
+client c1 {
+       txreq -hdr "Host: foo"
+       rxresp
+       expect resp.status == 200
+} -run



More information about the varnish-commit mailing list