]> err.no Git - varnish/commitdiff
Handle that the sessions may be killed the worker thread before
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 20 Nov 2007 14:20:36 +0000 (14:20 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 20 Nov 2007 14:20:36 +0000 (14:20 +0000)
we get around to delete the kevent.

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

varnish-cache/bin/varnishd/cache_acceptor_kqueue.c

index ed297cb2ea400c47735e12167a6b95eaa7c0e181..7621c944c934ecb922dc9026999d03d0ff8a8769 100644 (file)
@@ -125,7 +125,7 @@ vbit_test(struct vbitmap *vb, unsigned bit)
 static pthread_t vca_kqueue_thread;
 static int kq = -1;
 
-struct vbitmap *vca_kqueue_bits;
+static struct vbitmap *vca_kqueue_bits;
 
 static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
 
@@ -137,13 +137,25 @@ static unsigned nki;
 static void
 vca_kq_sess(struct sess *sp, short arm)
 {
+       int i;
 
        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
        if (sp->fd < 0)
                return;
        EV_SET(&ki[nki], sp->fd, EVFILT_READ, arm, 0, 0, sp);
        if (++nki == NKEV) {
-               AZ(kevent(kq, ki, nki, NULL, 0, NULL));
+               i = kevent(kq, ki, nki, NULL, 0, NULL);
+               assert(i <= 0);
+               if (i < 0) {
+                       /* 
+                        * We do not push kevents into the kernel before passing the session off
+                        * to a worker thread, so by the time we get around to delete the event
+                        * the fd may be closed and we get an ENOENT back once we do flush.
+                        *
+                        * XXX: Can we get EBADF if the client closes during this window ?
+                        */
+                       assert(errno == ENOENT);
+               }
                nki = 0;
        }
 }
@@ -188,6 +200,7 @@ vca_kev(const struct kevent *kp)
            sp, (unsigned long)kp->data, kp->flags,
            (kp->flags & EV_EOF) ? " EOF" : "");
 #endif
+       assert(sp->fd == kp->ident);
        if (kp->data > 0) {
                i = HTC_Rx(sp->htc);
                if (i == 0)
@@ -233,8 +246,10 @@ vca_kqueue_main(void *arg)
                assert(n >= 1 && n <= NKEV);
                nki = 0;
                for (kp = ke, j = 0; j < n; j++, kp++) {
-                       if (kp->flags & EV_ERROR)
+                       if (kp->flags & EV_ERROR) {
+                               /* See comment in vca_kq_sess() */
                                continue;
+                       }
                        if (kp->filter == EVFILT_TIMER) {
                                dotimer = 1;
                                continue;