Dreaded GROUP_BY issue on mySQL 5.7+
Looking at other issues, there are a few options to handle the GROUP BY issue on MySQL 5.6 > 5.7


Alter the query by using GROUP_CONCAT
Alter the SQL modes


Changing the SQL modes gives you a timeout, but these modes were given in a configuration file. Have you tried it by using an "extra" query?

I.E. session/global:

set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

This resets the SQL_MODE to ignore ONLY_FULL_GROUP_BY for every session, in a different way.

Let me know if this changes anything :)