swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

rollback异常 #321

Closed chongzi5210 closed 6 years ago

chongzi5210 commented 6 years ago
Q A
Bug report? yes/no
Feature request? yes/no
Swoft version 1.0.6
Swoole version swoole

swoole support => enabled Version => 4.0.1 Author => tianfeng.han[email: mikan.tenny@gmail.com] coroutine => enabled epoll => enabled eventfd => enabled timerfd => enabled signalfd => enabled cpu affinity => enabled spinlock => enabled rwlock => enabled async redis client => enabled async http/websocket client => enabled openssl => enabled Linux Native AIO => enabled pcre => enabled zlib => enabled mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled

Directive => Local Value => Master Value swoole.aio_thread_num => 2 => 2 swoole.display_errors => On => On swoole.use_namespace => On => On swoole.use_shortname => On => On swoole.fast_serialize => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608

| PHP version | PHP 7.1.14 (cli) (built: Feb 9 2018 17:34:55) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies | Runtime environment | Win10/Mac/CentOS 7/Ubuntu/Docker etc.

Details

Describe what you are trying to achieve and what goes wrong.

// paste output here

Provide minimal script to reproduce the issue

// paste code

不小心把数据表一个字段改掉了, 导致一个事务里面的sql异常, 发现一个比较奇怪的问题 ,异常被程序捕获了,做了回滚操作,发现异常处理里面rollback后面的逻辑未执行, rollback 里面抛出和sql 执行同样的错误。 rollback 执行不下去了咋办? 示例代码:

    Db::beginTransaction();

    try{
        //....

        Db::query('insert into xxxx ....')->getResult();

        //....
        Db::commit();
    }catch (\Throwable $e){
        var_dump('before rollback');
        Db::rollback();
        var_dump('after rollback');
        //....

    }

image

huangzhhui commented 6 years ago

可否提供一个可重现的Demo?

chongzi5210 commented 6 years ago

用上面的这个代码就可以测试 写一个不能执行的sql 语句就可以。

chongzi5210 commented 6 years ago

Swoft\Db\Driver\Mysql\MysqlConnection

image

image

chongzi5210 commented 6 years ago

不使用事务,也会有 Query 异常导致 getResult() 执行不到, 连接无法释放的问题

chongzi5210 commented 6 years ago

不使用事务,也会有 Query 异常导致 getResult() 执行不到, 连接无法释放的问题

这个原因我弄错了,不是getResult 执行不到, 应该是 DbCoResult getResult() line 29 $this->recv(true, false); 调用到MysqlConnection receive line 111触发异常导致

huangzhhui commented 6 years ago

关联issue #269

limingxinleo commented 6 years ago

https://github.com/swoft-cloud/swoft-component/pull/173

huangzhhui commented 6 years ago

https://github.com/swoft-cloud/swoft-db/releases/tag/v1.1.21