Rolling back transaction with trx_mysql_thread_id of 0 create deadlocks on update


I’m using MySQL 5.6.41 on AWS RDS.

I have seen, recently, lot of transactions ending as deadlocks.

Using SELECT * FROM information_schema.innodb_trx;

I found that a transaction was always there.

+--------------+--------------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+------------------+----------------------------+ |    trx_id    |  trx_state   |     trx_started     | trx_requested_lock_id | trx_wait_started | trx_weight | trx_mysql_thread_id | trx_query | trx_operation_state | trx_tables_in_use | trx_tables_locked | trx_lock_structs | trx_lock_memory_bytes | trx_rows_locked | trx_rows_modified | trx_concurrency_tickets | trx_isolation_level | trx_unique_checks | trx_foreign_key_checks | trx_last_foreign_key_error | trx_adaptive_hash_latched | trx_adaptive_hash_timeout | trx_is_read_only | trx_autocommit_non_locking | +--------------+--------------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+------------------+----------------------------+ | 294492387379 | ROLLING BACK | 2020-09-10 09:03:09 |                       |                  |   60603568 |                   0 |           |                     |                 0 |                 0 |             1911 |                194088 |            1676 |          60601657 |                       0 | REPEATABLE READ     |                 1 |                      1 |                            |                         0 |                     10000 |                0 |                          0 | +--------------+--------------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+------------------+----------------------------+ 

I have found a ROLLING BACK transaction with a trx_mysql_thread_id of 0. This transaction was the one blocking others.

To be sure, I ran this: SELECT * FROM information_schema.innodb_lock_waits;

+-------------------+-----------------------------+-----------------+-----------------------------+ | requesting_trx_id |      requested_lock_id      | blocking_trx_id |      blocking_lock_id       | +-------------------+-----------------------------+-----------------+-----------------------------+ |      294906405784 | 294906405784:426:27705081:4 |    294492387379 | 294492387379:426:27705081:4 | |      294906405563 | 294906405563:426:16826188:4 |    294492387379 | 294492387379:426:16826188:4 | +-------------------+-----------------------------+-----------------+-----------------------------+  

This command XA RECOVER; gives no results.

Is there a way to terminate the blocking transaction? Or find what is causing this?