Forum Discussion

mlick2's avatar
mlick2
Icon for Nimbostratus rankNimbostratus
Feb 13, 2009

Session limit jsessionid, closed connections

If using the sample iRule for HTTP session limit, how does the F5 know that the session is complete if the user is either redirected from the web server or just closes the connection. Also, how would we do this same logic only using a unique jessesionid for each user?

 

 

 

rule HTTP_session_limit {

 

when RULE_INIT {

 

set ::total_active_clients 0

 

set ::max_active_clients 100

 

log local0. "rule session_limit initialized: total/max: $::total_active_clients/$::max_active_clients"

 

}

 

when HTTP_REQUEST {

 

; test cookie presence

 

if {[HTTP::cookie exists "ClientID"]} {

 

set need_cookie 0

 

set client_id [HTTP::cookie "ClientID"]

 

; if cookie not present & connection limit not reached, set up client_id

 

} else {

 

if {$::total_active_clients < $::max_active_clients} {

 

set need_cookie 1

 

set client_id [format "%08d" [expr { int(100000000 * rand()) }]]

 

incr ::total_active_clients

 

; otherwise redirect

 

} else {

 

HTTP::redirect "http://sorry.domain.com/"

 

return

 

}

 

}

 

}

 

when HTTP_RESPONSE {

 

; insert cookie if needed

 

if {$need_cookie == 1} {

 

HTTP::cookie insert name "ClientID" value $client_id path "/"

 

}

 

}

 

when CLIENT_CLOSED {

 

; decrement current connection counter for this client_id

 

if {$::total_active_clients > 0} {

 

incr ::total_active_clients -1

 

}

 

}

 

}

 

1 Reply

  • I believe it knows by seeing a TCP connection close. Usually a packet request to close the connection. It can either be requested by the client, server or load balancer.

     

     

    Hope this helps

     

    CB