Skip to content

“Asymmetric transaction rollback error” if commit callbacks throw exceptions #6497

Closed
@schmengler

Description

@schmengler

Preconditions

  1. All current Magento 2 versions (2.0, 2.1.1)

Steps to reproduce

  1. Let a commit callback throw an exception

    Example:

    • create a new search engine
    <type name="Magento\Search\Model\AdapterFactory">
      <arguments>
        <argument name="adapters" xsi:type="array">
          <item name="dummy" xsi:type="string">Magento\Framework\Search\Adapter\Mysql\Adapter</item>
        </argument>
      </arguments>
    </type>
    
    • Do not register a corresponding indexer handler for Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory
    • The commit callback from the fulltext indexer plugin will cause an exception "There is no such indexer handler: dummy"
  2. Trigger this commit (for example, save a product)

Expected result

  1. Exception from the commit callback is thrown and can be catched later (for ex. by PHPUnit)

Actual result

  1. rollback() is called after commit() already has been called for the same transaction, resulting in an “Asymmetric transaction rollback error” exception when Magento tries to commit or rollback the last transaction on the stack.

Possible solution

  1. create a new exception type for exceptions during commit callbacks, AfterCommitException

  2. Replace throw $e with throw new AfterCommitException(null, null, $e); in AbstractResource::commit()

  3. In plugins that register commit callbacks, handle these exceptions separately:

        } catch (AfterCommitException $e) {
            throw $e->getPrevious();
        } catch (\Exception $e) {
            $productResource->rollBack();
            throw $e;
        }
    

Please let me know if this solution would be acceptable, before I create a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseimprovementup for grabs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions