Skip to content

Commit

Permalink
fixed failover bug, see issue #19
Browse files Browse the repository at this point in the history
  • Loading branch information
ulric committed Oct 29, 2015
1 parent 2f345d7 commit ca184cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pen.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ static void init(int argc, char **argv)
server = 0;

for (i = 1; i < argc; i++) {
DEBUG(2, "server[%d] = %s", server, argv[i]);
expand_servertable(server+1);
servers[server].status = 0;
servers[server].c = 0; /* connections... */
Expand All @@ -948,6 +949,7 @@ static void init(int argc, char **argv)
}

if (e_server) {
DEBUG(2, "Emergency server = %s", e_server);
expand_servertable(EMERGENCY_SERVER+1);
emerg_server = EMERGENCY_SERVER;
servers[EMERGENCY_SERVER].status = 0;
Expand All @@ -959,6 +961,7 @@ static void init(int argc, char **argv)
}

if (a_server) {
DEBUG(2, "Abuse server = %s", a_server);
expand_servertable(ABUSE_SERVER+1);
abuse_server = ABUSE_SERVER;
servers[ABUSE_SERVER].status = 0;
Expand Down
12 changes: 7 additions & 5 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ int initial_server(int conn)
if (!pd) {
DEBUG(1, "initial_server: denied by acl");
return abuse_server;
/* returning abuse_server is correct even if it is not set
because it defaults to NO_SERVER */
}
if (!(server_alg & ALG_ROUNDROBIN)) {
// Load balancing with memory == No roundrobin
Expand All @@ -220,19 +222,19 @@ int initial_server(int conn)
int failover_server(int conn)
{
int server = conns[conn].server;
DEBUG(2, "failover_server(%d)", conn);
DEBUG(2, "failover_server(%d): server = %d", conn, server);
if (server_alg & ALG_STUBBORN) {
DEBUG(2, "Won't failover because we are stubborn");
close_conn(conn);
return 0;
}
if (server == abuse_server) {
DEBUG(2, "Won't failover from abuse server");
if (server == ABUSE_SERVER) {
DEBUG(2, "Won't failover from abuse server (%d)", abuse_server);
close_conn(conn);
return 0;
}
if (server == emerg_server) {
DEBUG(2, "Already using emergency server, won't fail over");
if (server == EMERGENCY_SERVER) {
DEBUG(2, "Already using emergency server (%d), won't fail over", emerg_server);
close_conn(conn);
return 0;
}
Expand Down

0 comments on commit ca184cb

Please sign in to comment.