Forum Discussion
iRule to reselect pool member as a result of an HTTP Error Code
I'm attempting to capture HTTP status codes greater than 500, identify the node within the pool that is generating the error, and then force a retry to select a pool member that is "not" the problem node in the pool. The iRule can identify the error and increment the retries, but when a reselect is issued, the problem node is chosen most of the time. I have an "IF" statement within the "when LB_SELECTED" portion, that is attempting to compare the IP of current server in the pool against a member within the active_members list. If the IP of the current server matches the IP of an active member, I want to move to the next member in the active_members list and then force the reselect against that member. The problem is, that I can't seem to compare the two as strings to make the evaluation. Any thoughts?
Scenario :
LB method is RR
Two IIS servers in the pool, one is configured to always return a 503 status code.
iRule code:
Retry requests to the virtual server's default pool if the server responds with an error code (5xx status)
when CLIENT_ACCEPTED {
On each new TCP connection track that we have not retried a request yet
set retries 0
Save the name of the virtual server default pool
set default_pool [LB::server pool]
set pool_members [active_members -list $default_pool]
log local0. "Active members are: $pool_members"
}
when HTTP_REQUEST {
We only want to retry GET requests to avoid having to collect POST payloads
Only save the request headers if this is not a retried request
if { [HTTP::method] eq "GET" && $retries == 0 }{
set request_headers [HTTP::request]
log local0. "Saving HTTP request headers: $request_headers"
}
}
when LB_SELECTED {
Save the name of the node
set default_node [LB::server addr]
Select a new pool member from the VS default pool if we are retrying this request
if { $retries > 0 } {
foreach members $pool_members {
log local0. "$members"
if {!($members contains $default_node)}
{
log local0. "True. The bad node is being retried"
log local0. "$members is being retried."
log local0. "$default_node is the default node."
LB::reselect node $members
}
}
{LB::reselect}
}
}
when HTTP_RESPONSE {
Check for server errors
if { [HTTP::status] >= 500 } {
Server error, retry the request if we have not already retried more times than there are pool members
incr retries
log local0. "5xx error caught: retry $retries out of [active_members $default_pool]"
log local0. "Server IP is: $default_node"
if { $retries < [active_members $default_pool] } {
Retry this request
HTTP::retry $request_headers
Exit this event from this iRule so we do not reset retries to 0
return
}
}
If we are still in the rule we are not retrying this request
set retries 0
}
- dovesj_24220NimbostratusOk, there was a bit of confusion. I've confirmed that the retry does trigger the reselect to the "good" pool member. However, the page content is not returned correctly when the reselect succeeds. Still looking for assistance on this.
Recent Discussions
Related Content
* 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