Packets out of order. Error retrieving data from MariaDB

This appears to be an issue caused by using a cursor in the MySQL stored procedure you are calling. As a workaround, rather make use of a temporary table instead of a cursor, if possible.