r4561 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Sat Feb 13 21:24:55 CET 2010
Author: phk
Date: 2010-02-13 21:24:55 +0100 (Sat, 13 Feb 2010)
New Revision: 4561
Modified:
trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c
Log:
Be even more paranoid in the poll waiter.
Don't update the pollfd state from the pipe, until we have dealt with
all sessions.
Strongly assert the pollfd state everywhere.
Modified: trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c 2010-02-13 08:55:05 UTC (rev 4560)
+++ trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c 2010-02-13 20:24:55 UTC (rev 4561)
@@ -86,9 +86,14 @@
assert(fd >= 0);
vca_pollspace((unsigned)fd);
assert(fd < npoll);
+
if (hpoll < fd)
hpoll = fd;
+
assert(pollfd[fd].fd == -1);
+ assert(pollfd[fd].events == 0);
+ assert(pollfd[fd].revents == 0);
+
pollfd[fd].fd = fd;
pollfd[fd].events = POLLIN;
}
@@ -97,10 +102,14 @@
vca_unpoll(int fd)
{
+ assert(fd >= 0);
assert(fd < npoll);
- assert(fd >= 0);
vca_pollspace((unsigned)fd);
+
assert(pollfd[fd].fd == fd);
+ assert(pollfd[fd].events == POLLIN);
+ assert(pollfd[fd].revents == 0);
+
pollfd[fd].fd = -1;
pollfd[fd].events = 0;
}
@@ -125,33 +134,19 @@
while (hpoll > 0 && pollfd[hpoll].fd == -1)
hpoll--;
assert(vca_pipes[0] <= hpoll);
- assert(pollfd[vca_pipes[0]].fd = vca_pipes[0]);
- assert(pollfd[vca_pipes[1]].fd = -1);
+ assert(pollfd[vca_pipes[0]].fd == vca_pipes[0]);
+ assert(pollfd[vca_pipes[1]].fd == -1);
v = poll(pollfd, hpoll + 1, 100);
assert(v >= 0);
- if (v && pollfd[vca_pipes[0]].revents) {
-
- if (pollfd[vca_pipes[0]].revents != POLLIN)
- VSL(SLT_Debug, 0, "pipe.revents= 0x%x",
- pollfd[vca_pipes[0]].revents);
- assert(pollfd[vca_pipes[0]].revents == POLLIN);
- v--;
- i = read(vca_pipes[0], ss, sizeof ss);
- assert(i >= 0);
- assert(((unsigned)i % sizeof ss[0]) == 0);
- for (j = 0; j * sizeof ss[0] < i; j++) {
- CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC);
- assert(ss[j]->fd >= 0);
- VTAILQ_INSERT_TAIL(&sesshead, ss[j], list);
- vca_poll(ss[j]->fd);
- }
- }
deadline = TIM_real() - params->sess_timeout;
VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
if (v == 0)
break;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
fd = sp->fd;
+ assert(fd >= 0);
+ assert(fd <= hpoll);
+ assert(fd < npoll);
assert(pollfd[fd].fd == fd);
if (pollfd[fd].revents) {
v--;
@@ -159,6 +154,7 @@
if (pollfd[fd].revents != POLLIN)
VSL(SLT_Debug, fd, "Poll: %x / %d",
pollfd[fd].revents, i);
+ pollfd[fd].revents = 0;
VTAILQ_REMOVE(&sesshead, sp, list);
if (i == 0) {
/* Mov to front of list for speed */
@@ -175,6 +171,24 @@
SES_Delete(sp);
}
}
+ if (v && pollfd[vca_pipes[0]].revents) {
+
+ if (pollfd[vca_pipes[0]].revents != POLLIN)
+ VSL(SLT_Debug, 0, "pipe.revents= 0x%x",
+ pollfd[vca_pipes[0]].revents);
+ assert(pollfd[vca_pipes[0]].revents == POLLIN);
+ pollfd[vca_pipes[0]].revents = 0;
+ v--;
+ i = read(vca_pipes[0], ss, sizeof ss);
+ assert(i >= 0);
+ assert(((unsigned)i % sizeof ss[0]) == 0);
+ for (j = 0; j * sizeof ss[0] < i; j++) {
+ CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC);
+ assert(ss[j]->fd >= 0);
+ VTAILQ_INSERT_TAIL(&sesshead, ss[j], list);
+ vca_poll(ss[j]->fd);
+ }
+ }
assert(v == 0);
}
NEEDLESS_RETURN(NULL);
More information about the varnish-commit
mailing list