MariaDB InnoDB does not rollback on timeout
What is the client?  Does it have &quot;auto reconnect&quot; turned on?  Turn it off.
What I think is happening:

The UPDATE croaks (in any way) and gets rolled back.
The connection is reestablished, perhaps with autocommit.
The INSERT runs successfully and autocommits.
The COMMIT is silently ignored.

Put error checks after every SQL statement.