From what I understand, you’ve got a function in your app that causes a deadlock. You should first create the app so it can handle deadlocks. Still, if that’s out of the question, the config from above, with “option mysql-check user haproxy” should work properly.
When there’s no deadlock, it will load balance among the two servers. When one is having a lock, the queries should be sent to the other server. Still, I think that this can cause an issue when the two servers will try to sync, because each will have data written in them at the same time, on the same row, basically, as db-02 is unaware that db-01 is already writing. I could be wrong though…
Still, as I said, deadlocks are a MySQL thing and apps should have a mechanism to work (retry transaction after a few seconds or something) even if they hit a lock. HAProxy’s job is to load balance / failover, not to avoid a MySQL issue, so you’re tackling the issue from the wrong perspective. If I were you, I’d tackle this from the app perspective / DB perspective (get faster disks, use more threads, etc, depending on what’s slowing the DB down).