The `set_more_tries` function can allow `balancer_by_lua` to be invoked multiple times during a single request. For example, if you call `set_more_tries(1)` before the request is sent to the upstream, if the upstream request fails with a status code configured in `proxy_next_upstream`, `balancer_by_lua` will be called again for the request. You can continue to call `set_more_tries`, and NGINX will continue to invoke `balancer_by_lua` on failures until you've reached `proxy_next_upstream_tries` at which point the downstream request will fail.
It's up to you to decide how to respond to a failing upstream. You can call `set_current_peer` and simply set different host/port upstream if/when the upstream request fails.