[MINOR] Allow shutdown of sessions when a server becomes unavailable
This adds the "on-marked-down shutdown-sessions" statement on "server" lines,
which causes all sessions established on a server to be killed at once when
the server goes down. The task's priority is reniced to the highest value
(1024) so that servers holding many tasks don't cause a massive slowdown due
to the wakeup storm.
diff --git a/src/checks.c b/src/checks.c
index 82aceaa..6b34a37 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -45,6 +45,7 @@
#include <proto/proto_tcp.h>
#include <proto/proxy.h>
#include <proto/server.h>
+#include <proto/session.h>
#include <proto/stream_interface.h>
#include <proto/task.h>
@@ -357,6 +358,24 @@
return xferred;
}
+/* Shutdown connections when their server goes down.
+ */
+static void shutdown_sessions(struct server *srv)
+{
+ struct session *session, *session_bck;
+
+ list_for_each_entry_safe(session, session_bck,
+ &srv->actconns, by_srv) {
+ if (session->srv_conn == srv &&
+ !(session->req->flags & (BF_SHUTW|BF_SHUTW_NOW))) {
+ buffer_shutw_now(session->req);
+ buffer_shutr_now(session->rep);
+ session->task->nice = 1024;
+ task_wakeup(session->task, TASK_WOKEN_OTHER);
+ }
+ }
+}
+
/* Sets server <s> down, notifies by all available means, recounts the
* remaining servers on the proxy and transfers queued sessions whenever
* possible to other servers. It automatically recomputes the number of
@@ -380,6 +399,9 @@
s->state &= ~(SRV_RUNNING | SRV_GOINGDOWN);
s->proxy->lbprm.set_server_status_down(s);
+ if (s->onmarkeddown & HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS)
+ shutdown_sessions(s);
+
/* we might have sessions queued on this server and waiting for
* a connection. Those which are redispatchable will be queued
* to another server or to the proxy itself.