Forum Discussion

admin_xk_99638's avatar
admin_xk_99638
Icon for Nimbostratus rankNimbostratus
Mar 13, 2012

can't read "need_cookie": no such variable

Hi All, Encounter the following errors.

 

 

 

Mar 9 10:00:01 local/tmm err tmm[4875]: 01220001:3: TCL error: MAGIC-iRules - can't read "need_cookie": no such variable while executing "if {$need_cookie == 1} { HTTP::cookie insert name "magicClientName" value "TM2003218" HTTP::cookie insert name "TM2003218" value $client_id..."

 

 

Any advice on this?

 

 

Is it because the need_cookie contains the special characters?

 

 

  • Is it because the need_cookie contains the special characters?i do not think so.

     

     

    Any advice on this?may you post the whole irule?
  • when RULE_INIT {

     

    ; set ::total_active_clients 0

     

    ; set ::max_active_clients 3000

     

    set ::holding_page_be "http://www.testing.com"

     

    set ::debug_mode 0

     

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

     

    }

     

     

    when HTTP_REQUEST {

     

    ; test cookie presence

     

    if {[HTTP::uri] contains "maxLimit.do"} {

     

    if {[HTTP::cookie value "SeatOfferPage"] == "successful"} {

     

    log local0. "TE kick out user after step 1!"

     

    }

     

    }

     

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

     

    set need_cookie 0

     

    set client_id [HTTP::cookie "TM2003218"]

     

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

     

    ;log local0. "old client id $client_id, current number $::total_active_clients"

     

    if {$::debug_mode >= 4} {log local0. "Returning customer with cookie value: $client_id"}

     

    } else {

     

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

     

    if {[HTTP::uri] contains "SeatAvailability.do"} {

     

    set need_cookie 1

     

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

     

    if {$::debug_mode >= 1} {log local0. "1-New customer with cookie value: $client_id, IP:[IP::client_addr], total_active_clients: $::total_active_clients"}

     

    incr ::total_active_clients

     

    ; otherwise redirect

     

    ;log local0. "new client id $client_id, current number $::total_active_clients"

     

    }

     

    } else {

     

    ; set need_cookie 2

     

    if {$::debug_mode >= 2} {log local0. "Excced limit now, total_active_clients: $::total_active_clients"}

     

    HTTP::respond 302 Location $::holding_page_te "Cache-Control" "no-cache" "Pragma" "no-cache"

     

    return

     

    }

     

    }

     

    }

     

    when HTTP_RESPONSE {

     

     

    ; insert cookie if needed

     

    if {$need_cookie == 1} {

     

    HTTP::cookie insert name "magicClientName" value "TM2003218"

     

    HTTP::cookie insert name "TM2003218" value $client_id

     

    }

     

     

    ; if {$need_cookie == 2} {

     

    ; HTTP::respond 302 Location $::holding_page_te "Cache-Control" "no-cache" "Pragma" "no-cache"

     

    ; return

     

    ; }

     

     

    }

     

    when CLIENT_CLOSED {

     

    ; decrement current connection counter for this client_id

     

    if {$::total_active_clients > 0} {

     

    incr ::total_active_clients -1

     

    if {$::debug_mode >= 1} {log local0. "Client dropped, total_active_clients: $::total_active_clients"}

     

    }

     

    }
  • It looks like you are only setting the need_cookie variable under certain conditions. So on any requests where those conditions are not met the variable $need_cookie is not set.

     

    You need to ALWAYS set the need_cookie variable to some value (like at the top of the irule where you are setting the other variables) since you are calling for it unconditionally under the HTTP_RESPONSE event. Hope that makes sense.

     

    -Joe

     

  • if I insert set ::need_cookie below the set ::debug_mode 0 does it helps? Will it considered as setting it as global variable?
  • shouldn't need_cookie be local variable rather than global one?

     

     

    instead of setting it in RULE_INIT, i think it should be initialized in HTTP_REQUEST.