Forum Discussion
LB_SELECTED is processed twice when doing LB::RESELECT
I've got the following code to reselect which backend gets hit based on what response code we get from the initial request:
when CLIENT_ACCEPTED {
set retries 0
set debug 5
set default_pool pool_media_transcoding
}
when HTTP_REQUEST {
pool $default_pool
if { $retries == 0 } {
set request [HTTP::request]
}
if { $debug > 4 } { log local0. "HTTP_REQUEST - Retries : $retries - Request: $request" }
}
when LB_SELECTED {
if { $debug > 0 } { log local0. "when LB_SELECTED : Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" }
if { $retries == 0 } {
Log LB pool/server selection
if { $debug > 0 } { log local0. "Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" }
} else {
Reselect LB node if retries > 0
if { $debug > 0 } { log local0. "Retries : $retries. wanted host/port = $wantedhost:$wantedport" }
LB::reselect pool dev-pool_media_transcoding member $wantedhost $wantedport
LB::reselect pool dev-pool_media_transcoding
LB::reselect node $wantedhost $wantedport
Log LB pool/server selection
if { $debug > 0 } { log local0. "Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" }
}
}
when SERVER_CONNECTED {
if {$debug > 0}{log local0. "[IP::client_addr]:[TCP::client_port]: Server IP:port: [IP::server_addr]:[TCP::server_port]"}
}
when HTTP_RESPONSE {
if { [HTTP::status] eq 302 && $retries == 0 } {
if {[HTTP::header X-TRANSCODE-REDIRECT-HOST] eq ""}{
if { $debug > 0 } { log local0. "We got 302 from backend, but no X-TRANSCODE-REDIRECT-HOST header set" }
} else {
set wantedhost [lindex [split [HTTP::header X-TRANSCODE-REDIRECT-HOST] ":"] 0]
set wantedport [lindex [split [HTTP::header X-TRANSCODE-REDIRECT-HOST] ":"] 1]
if { $debug > 0 } { log local0. "We got 302 from backend. It wants us to redirect to $wantedhost : $wantedport" }
incr retries
HTTP::retry "$request"
}
} else {
set retries 0
}
}
The "problem" is that LB_SELECTED gets processed twice when retries=1. Why is that? When the HTTP::Retry happens I expected the request to go through to the reselected backend when it is set, but it seems it runs through LB_SELECTED again?
- ingard
Nimbostratus
Log output:
May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : HTTP_REQUEST - Retries : 0 - Request: GET /segment/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZDUiOiJlZWYyMjAyZjg2ZGNjMDM0MmZiMjQ4ODExMTlkZjRlYyIsInVzZXJuYW1lIjoiZmF6ZXJtaW50ODIifQ.rNIkeMsXJfjPh7dlr1XkmY5uhRKuWeEz-4AcjIxRZqo/SD/segment000.ts HTTP/1.1 Host: domain.com User-Agent: curl/7.46.0 Accept: */* X-Forwarded-For: 1.2.3.4 jx_scheme: https May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : when LB_SELECTED : Retries : 0 - Server Selected : /Common/pool_media_transcoding 10.0.70.110:8105 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 0 - Server Selected : /Common/pool_media_transcoding 10.0.70.110:8105 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : 1.2.3.4:20343: Server IP:port: 10.0.70.110:8105 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : We got 302 from backend. It wants us to redirect to 10.0.70.110 : 8106 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : HTTP_REQUEST - Retries : 1 - Request: GET /segment/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZDUiOiJlZWYyMjAyZjg2ZGNjMDM0MmZiMjQ4ODExMTlkZjRlYyIsInVzZXJuYW1lIjoiZmF6ZXJtaW50ODIifQ.rNIkeMsXJfjPh7dlr1XkmY5uhRKuWeEz-4AcjIxRZqo/SD/segment000.ts HTTP/1.1 Host: domain.com User-Agent: curl/7.46.0 Accept: */* X-Forwarded-For: 1.2.3.4 jx_scheme: https May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : when LB_SELECTED : Retries : 1 - Server Selected : /Common/pool_media_transcoding 10.0.70.110:8105 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1. wanted host/port = 10.0.70.110:8106 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1 - Server Selected : 10.0.70.110:8106 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : when LB_SELECTED : Retries : 1 - Server Selected : 10.0.70.110:8106 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1. wanted host/port = 10.0.70.110:8106 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1 - Server Selected : 10.0.70.110:8106 May 3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : 1.2.3.4:20343: Server IP:port: 10.0.70.110:8106
- Kevin_Davies_40
Nacreous
The short answer is the retry command means the F5 will try another server. When it does, the event fires again because it is selecting another server. If you don't want that to happen use the command event disable. This means it will not trigger that event again even if it selects another server. The command tells the F5 to turn off this iRule event. It won't be triggered again for the remainder of that connection. The scope of the command is for that connection only.
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