For the background on this task, see private, very specific task T149076.
MySQL servers have a watchdog where webrequest user's queries are killed after 300 seconds. Sometimes, the watchdog (because deployment bugs T148790) fails. Sometimes, even if it works as indented, multiple long running queries can affect availability of services such as MySQL. By the time the queries are ongoing, it is too late to do something about them- mysql is saturated. Multiple long requests should be cut short at application server level, not at the lower levels (or in addition).
In theory, this should be handled by configuration such as https://gerrit.wikimedia.org/r/#/c/206440/ -in reality, MySQL queries (when not killed by MySQL watchdog) continue for hours (e.g. T148822). The suspicions is that either the above commit is not working or has been reverted; or queries are not fully killed when the mediawikiki thread request iself errors-out or it is killed, leaving orphan queries (thread handling bug or mysqli bug). Investigate where the issue is, and solve it or workaround it somehow.