Forum Discussion

David_L_'s avatar
David_L_
Icon for Nimbostratus rankNimbostratus
Sep 10, 2007

TCL IF/Else processing problem?

I'm using an iRule to manually manipulate the persistence table - adding a persistence record on login and deleting it on logout. I'm seeing a behavior I can't explain - perhaps someone here can help?

 

 

For the most part this works as expected. Persistence appears to be maintained correctly. The problem is that when I look at the log entries created by this rule I see:

 

 

... Added Added persistence for session XXXXXX (as expected on login)

 

... Updated persistence for session XXXXXX (repeated many times as expected)

 

... Deleted persistence for session (as expected on logout)

 

... Updated persistence for session XXXXXX (This line is the problem!)

 

 

Why is the "Else" statement apparently being executed after the "If" condition is met and statement executed? Am I missing something fundamental about this?

 

Thanks!

 

 

The iRule is:

 

-------------------------------------------------------

 

when CLIENT_ACCEPTED {

 

set add_persist 1

 

}

 

when HTTP_RESPONSE {

 

if { [HTTP::cookie exists "JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "JSESSIONID"] 1800

 

set add_persist 0

 

log local0. " Added persistence for session [HTTP::cookie "JSESSIONID"]"

 

}

 

}

 

when HTTP_REQUEST {

 

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

 

persist delete uie [HTTP::cookie "JSESSIONID"]

 

log local0. " Deleted persistence for session [HTTP::cookie "JSESSIONID"]"

 

} else {

 

persist uie [HTTP::cookie "JSESSIONID"] 1800

 

log local0. " Updated persistence for session [HTTP::cookie "JSESSIONID"]"

 

}

 

}

 

------------------------------------------------------------

1 Reply

  • Are you sure that the else statement is being executed in the same request? Try adding some more logging at the entry to HTTP_REQUEST and we'll see...

    when HTTP_REQUEST {
      log local0. "Received HTTP Request for URI: [HTTP::uri]"
      if { [HTTP::uri] contains "logout.do"} {
        persist delete uie [HTTP::cookie "JSESSIONID"]
        log local0. " Deleted persistence for session [HTTP::cookie "JSESSIONID"]"
      } else {
        persist uie [HTTP::cookie "JSESSIONID"] 1800
        log local0. " Updated persistence for session [HTTP::cookie "JSESSIONID"]"
      }
    }

    Odds are there's another requests slipping in there not containing "logout.do" after your logout.do request.

    -Joe