Waiting room iRule
Hi Guys,
I am working on the below iRule. The logic is to send the user to a waiting room once we have enough sessions already active on a website. However after applying the iRule I am getting the server unreachable error. Please check the logic below and advise how can I make it work. The datagroup is created separately with the values as mentioned in the iRule;
when HTTP_REQUEST priority 1 {
Lookup and set value for maxActiveClients using the max_active_clients value in the datagroup_customer data group.
set static::maxActiveClients "[class search -all -value datagroup_customer starts_with "max_active_clients"]"
Hardcoded subtable name used to make sure the sub table is consistent across any VIPS the iRule is applied to
set subtableName "sessionLimit"
Lookup and set value for sessionCookieName using the session_cookie_prefix value in the datagroup_customer data group.
set sessionCookieName "[class search -all -value datagroup_customer starts_with "session_cookie_prefix"]"
Lookup and set value for holdingPage using the holding_page_url value in the datagroup_customer data group.
set holdingPage "[class search -all -value datagroup_customer starts_with "holding_page_url"]"
Set need_cookie to zero. If the user requries a cookie, this value gets changed to 1
set need_cookie 0 ; test cookie presence if {[HTTP::cookie exists $sessionCookieName]} { set client_id [HTTP::cookie $sessionCookieName]
Check the session still exists
set sessiondata [table lookup -subtable $subtableName $client_id] if { $sessiondata != "" } {
Valid session found in sub table. The lookup resets the cookie timer so continue on. log local0. "Valid session $client_id - continuing"
return } }
If there is no cookie present, there is not a valid session in the sub table so need to issue cookie. Check capacity before issuing a cookie log local0. "No session. Checking for free slot (Max $static::maxActiveClients)"
set sessionCount [table keys -subtable $subtableName -count]
log local0. "No session. Checking for free slot (Current $sessionCount)"
if {$sessionCount < $static::maxActiveClients} {
There is enough capacity. Allocate the session and set the session cookie on the client
set need_cookie 1 set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] set sessionValue [IP::client_addr]
Add session information to the sub table
table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout
log local0. "New Session ($client_id) added value $sessionValue Timeout $static::sessionTimeout"
} else {
No available capacity. Redirect client to holding page.
HTTP::redirect $holdingPage } } when HTTP_RESPONSE priority 1 { ; insert cookie if needed if {$need_cookie == 1} { HTTP::cookie insert name $sessionCookieName value $client_id path "/" } }