Forum Discussion
Catching an exception in irule for a nonexistent pool
How would I catch an exception for a nonexistent pool? I have this irule hardwired to return a 503:
when HTTP_REQUEST {
set HOST [ string tolower [HTTP::host] ]
set VALUE "/"
set MYPOOL [ call /Common/LIB-sac-dev::https_rule $HOST $VALUE ]
log local0.debug "HERE: Pool $MYPOOL Host $HOST Value $VALUE"
HTTP::respond 503 content "Pool \"$MYPOOL\" unavailable"
event disable
TCP::close
pool $MYPOOL
The call returns a pool name according to the host name in the header. If the host name doesn't match a pool, it returns the string "undefined". When MYPOOL exists, the rules correctly responds with a 503:
Unexpectedly, if the pool does not exist, the "pool" statement is evaluated, no 503 response occurs and the browser gets a 'connection reset' instead:
- no such pool: undefined (line 😎 invoked from within "pool $MYPOOL"
How could I send a 503 in response to a ltm rule that contains a reference to a nonexistent pool?
Hi Wsanders,
you may take a look to the iRule below. It uses an
if { [catch { some code which may fail }] } then { error handle if code has been failed }
syntax, to check if the pool name fetched from your datagroup is valid and if the pool has any active members.
when HTTP_REQUEST { Getting destination pool name based on HOST and Path set HOST [ string tolower [HTTP::host] ] set VALUE "/" set MYPOOL [ call /Common/LIB-sac-dev::https_rule $HOST $VALUE ] log local0.debug "HERE: Pool $MYPOOL Host $HOST Value $VALUE" Checking if pool exists and has any active members. if { [catch { Lets try if the code below works (it will if $MYPOOL contains a valid pool name...) if { [active_members $MYPOOL] == 0 } then { The pool does exist but has no available members (aka. no TCL error but [active_members] was equal 0) HTTP::respond 503 content "Pool \"$MYPOOL\" is unavailable" "Connection" "close" event disable TCP::close } else { The pool does exist and has available members (aka. no TCL error and [active_members] was greater than 0) pool $MYPOOL } }] } then { Something went wrong with the code above. Seems that the pool does not exist (aka. a TCL runtime error ocoured) log local0.debug "ErrorInfo: [subst "\$::errorInfo"]" HTTP::respond 502 content "Bad Gateway - invalid HTTP request" "Connection" "close" event disable TCP::close } }
Cheers, Kai
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