Where in the HAproxy C code repo is the part responsible of handling the failure of a server and falling back to a backup one?

I’m trying to understand why instead of the fallback mechanism of haproxy working (in case of sticky connections) I’m getting 504 gateway timeout errors when a server fails although there are other backup servers available to handle the requests. So, I’m currently studying the C code of haproxy and would appreciate any pointers.

I tried increasing the “timeout server” config value in the haproxy configuration file from 3000ms to 30000ms and that eliminated the 504 errors but that solution wasn’t accepted by the team leader because he said we cannot afford such a long timeout period.

I suggest reading the documentation about “option redispatch” and “retry-on”.

I did check them both and I found that the configuration file already has them.
With retry-on all-retryable-errors.

Documented limitations apply.

Is there a chance that sticky session [session persistence] is not working well with option redispatch?
Something like, session persistence is not allowing redispatching sometimes?

In any case, it would be of great help, if a hint can be provided to the implementation of ‘option redispatch’ in current C code. [for example file name or function name]

best regards

I don’t know the exact code paths in the source code.

Please read the documentation about option redispatch:


It explains the scenario very well.