Forum Discussion
John_Boyd_45868
Nimbostratus
Jun 29, 2006using 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
- JRahm
Admin
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" } }
- John_Boyd_45868
Nimbostratus
Oh! sorry, we're running 9.1.1 (I should have mentioned). So the LB:: commands won't work.. - JRahm
Admin
Try [LB::server pool] instead of selected. Also update my entry with the name of the cookie on lines 3/8. Sorry about that. - John_Boyd_45868
Nimbostratus
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. - Deb_Allen_18Historic F5 AccountIt 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.
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]" }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects