I had a similar error and ended up being an issue with the high number of records (400k+) processed by the query. I am not sure whether this could be related to your case, but using indexes (and even better with partial_filter_selector) solved it for me.