]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MAJOR: checks: don't call set_server_status_* when no LB algo is set
authorWilly Tarreau <w@1wt.eu>
Sat, 19 May 2012 17:07:40 +0000 (19:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 19 May 2012 17:09:46 +0000 (19:09 +0200)
David Touzeau reported that haproxy dies when a server is checked and is
used in a farm with only "option transparent" and no LB algo. This is
because the LB params are NULL, the functions should be checked before
being called.

The same bug is present in 1.4 so this patch must be backported.

include/types/backend.h
src/checks.c
src/dumpstats.c

index 8672bd2465942f9b26a7e1f484e45925666561ed..fd66e407a6acfde752ec0e7dadabd642830bb79b 100644 (file)
@@ -134,7 +134,7 @@ struct lbprm {
        struct lb_fwlc fwlc;
        struct lb_chash chash;
        struct lb_fas fas;
-       /* Call backs for some actions. Some may be NULL (thus should be ignored). */
+       /* Call backs for some actions. Any of them may be NULL (thus should be ignored). */
        void (*update_server_eweight)(struct server *);  /* to be called after eweight change */
        void (*set_server_status_up)(struct server *);   /* to be called after status changes to UP */
        void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN */
index 78ec4ad6dd7a2d5309054804fee24dd9cdbc11c2..febf77e7b7a09e766fd1f1d31ff909112419fdcb 100644 (file)
@@ -390,7 +390,8 @@ void set_server_down(struct server *s)
 
                s->last_change = now.tv_sec;
                s->state &= ~(SRV_RUNNING | SRV_GOINGDOWN);
-               s->proxy->lbprm.set_server_status_down(s);
+               if (s->proxy->lbprm.set_server_status_down)
+                       s->proxy->lbprm.set_server_status_down(s);
 
                if (s->onmarkeddown & HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS)
                        shutdown_sessions(s);
@@ -476,7 +477,8 @@ void set_server_up(struct server *s) {
                        }
                        task_schedule(s->warmup, tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20))));
                }
-               s->proxy->lbprm.set_server_status_up(s);
+               if (s->proxy->lbprm.set_server_status_up)
+                       s->proxy->lbprm.set_server_status_up(s);
 
                /* check if we can handle some connections queued at the proxy. We
                 * will take as many as we can handle.
@@ -521,7 +523,8 @@ static void set_server_disabled(struct server *s) {
        int xferred;
 
        s->state |= SRV_GOINGDOWN;
-       s->proxy->lbprm.set_server_status_down(s);
+       if (s->proxy->lbprm.set_server_status_down)
+               s->proxy->lbprm.set_server_status_down(s);
 
        /* we might have sessions queued on this server and waiting for
         * a connection. Those which are redispatchable will be queued
@@ -558,7 +561,8 @@ static void set_server_enabled(struct server *s) {
        int xferred;
 
        s->state &= ~SRV_GOINGDOWN;
-       s->proxy->lbprm.set_server_status_up(s);
+       if (s->proxy->lbprm.set_server_status_up)
+               s->proxy->lbprm.set_server_status_up(s);
 
        /* check if we can handle some connections queued at the proxy. We
         * will take as many as we can handle.
index b95418e94bffc04382d0ff4e35aa6ac2fa0063af..4b051d7bf085cb9eac04cce3a22a06257a905684 100644 (file)
@@ -989,10 +989,14 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                        /* static LB algorithms are a bit harder to update */
                        if (px->lbprm.update_server_eweight)
                                px->lbprm.update_server_eweight(sv);
-                       else if (sv->eweight)
-                               px->lbprm.set_server_status_up(sv);
-                       else
-                               px->lbprm.set_server_status_down(sv);
+                       else if (sv->eweight) {
+                               if (px->lbprm.set_server_status_up)
+                                       px->lbprm.set_server_status_up(sv);
+                       }
+                       else {
+                               if (px->lbprm.set_server_status_down)
+                                       px->lbprm.set_server_status_down(sv);
+                       }
 
                        return 1;
                }