Forum Discussion

John_Boyd_45868's avatar
John_Boyd_45868
Icon for Nimbostratus rankNimbostratus
Jun 29, 2006

using a new pool based on cookie

Because of a concurrency bug in our application I'm trying to only allow one appserver to write to our database. I removed 1 of the 4 appservers from our "main" pool and put it into its own pool "login1". Then I wrote a simple iRule to test if the cookie "username" exists (they've logged in) and direct that session to the pool "login1" (the writeable server). I tried it and nothing happended. Then I turned off cookie persistence on "main", restested, and it still stays in the "main" pool. Any ideas why this would happen?

 

 

Here is the test iRule:

 

 

 

when HTTP_REQUEST {

 

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

 

use pool login1

 

} else {

 

use pool main

 

}

 

}

 

 

 

Thanks,

 

 

John Boyd

5 Replies

  • Add some logging to determine where your problems lie:

    
    when HTTP_RESPONSE {
      if { [HTTP::cookie exists "username"] } {
        log "If: username cookie from server, contents are: [HTTP::cookie]"
      }
    }
    when HTTP_REQUEST {
      if {[HTTP::cookie exists "username"]} {
        log "If: username cookie from client, contents are: [HTTP::cookie]"
        log "If: Current pool is [LB::server pool]"
        use pool login1
        log "If: Pool set to [LB::server pool] by iRule"
      } else {
        log "Else: Default pool is [LB::selected pool]"
        use pool main
        log "Else: Pool set to [LB::server pool] by iRule"
      }
    }
  • Oh! sorry, we're running 9.1.1 (I should have mentioned). So the LB:: commands won't work..

     

     

    I replaced my iRule with yours and got these errors:

     

     

    01070151:3: Rule [login] error:

     

    line 3: [wrong args] [HTTP::cookie]

     

    line 8: [wrong args] [HTTP::cookie]

     

    line 13: [undefined procedure: LB::selected] [LB::selected pool]

     

     

     

    john
  • Try [LB::server pool] instead of selected. Also update my entry with the name of the cookie on lines 3/8. Sorry about that.
  • So, I logged in just before the break between 13:46 and 13:47 (below). It seems to show the correct pool momentarily but it never goes to that server, then it sets itself back to the default pool "main" even though the cookie "username" still exists.

     

     

    Here is the tail -f of the log:

     

     

    Jun 29 13:46:55 tmm tmm[719]: Rule login : If: Current pool is main

     

    Jun 29 13:46:55 tmm tmm[719]: Rule login : If: Pool set to login1 by iRule

     

    Jun 29 13:46:55 tmm tmm[719]: Rule login : If: username cookie from client, contents are: If-Modified-Since: Tue, 20 Jun 2006 20:05:34 GMT

     

    Jun 29 13:46:55 tmm tmm[719]: Rule login : If: Current pool is

     

    Jun 29 13:46:55 tmm tmm[719]: Rule login : If: Pool set to login1 by iRule

     

     

     

    Jun 29 13:47:01 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:01 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:02 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:02 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Default pool is

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:06 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:07 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:08 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:12 tmm tmm[719]: Rule login : If: username cookie from client, contents are: If-Modified-Since: Thu, 29 Jun 2006 19:30:38 GMT

     

    Jun 29 13:47:12 tmm tmm[719]: Rule login : If: Current pool is main

     

    Jun 29 13:47:12 tmm tmm[719]: Rule login : If: Pool set to login1 by iRule

     

    Jun 29 13:47:14 tmm tmm[719]: Rule login : If: username cookie from server, contents are:

     

    Jun 29 13:47:24 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:24 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:24 tmm tmm[719]: Rule login : If: username cookie from server, contents are:

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: username cookie from client, contents are: Content-Type: application/x-www-form-urlencoded

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: Current pool is main

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: Pool set to login1 by iRule

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: username cookie from server, contents are: qspel12

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: username cookie from client, contents are: qspel12

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: Current pool is main

     

    Jun 29 13:47:33 tmm tmm[719]: Rule login : If: Pool set to login1 by iRule

     

    Jun 29 13:47:34 tmm tmm[719]: Rule login : If: username cookie from server, contents are:

     

    Jun 29 13:47:40 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:40 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:48 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:48 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : If: username cookie from server, contents are:

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : If: username cookie from client, contents are: If-Modified-Since: Thu, 29 Jun 2006 19:30:48 GMT

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : If: Current pool is main

     

    Jun 29 13:47:52 tmm tmm[719]: Rule login : If: Pool set to login1 by iRule

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Default pool is main

     

    Jun 29 13:47:53 tmm tmm[719]: Rule login : Else: Pool set to main by iRule

     

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    It actually looks like the basic rule logic is good (simple enough!), but the logging is picking up some random header info instead of the actual cookie values, and the selected pool also won't be known until the LB_SELECTED event.

    So let's clean up the test as citizen elah suggested, add an LB_SELECTED event, grab the server-set cookie values, and test again:
    when HTTP_RESPONSE {
      if { [HTTP::header exists Set-Cookie] } {
        log "If: server is setting these cookies: [HTTP::header Set-Cookie]"
      }
    }
    when HTTP_REQUEST {
      log "Current pool is [LB::server pool]"
      if {[HTTP::cookie exists username]} {
        log "If: username cookie from client, contents are: [HTTP::cookie username]"
        use pool login1
      } else {
        log "Else: No username cookie from client"
        use pool main
      }
    }
    when LB_SELECTED {
      log "Selected pool is [LB::server pool]"
    }

    Post back with more info if you run into further trouble.

    HTH

    /deb